迁移到New客户端https://developers.google.com/places/android-sdk/client-migration
我正在尝试使用Embed a AutocompleteFragment进行迁移,显然它在接收到所选位置的返回时才正确工作,因为下面的代码允许打开片段、输入位置并在列表中选择它,但在此之后,将显示下面报告的错误,并且不执行或onError()例程。
以下代码布局:
<fragment
android:id="@+id/autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment" />
以下代码函数:
public void mostraPesquisa(boolean set) {
if (MainActivity.this.isDestroyed()) return;
if (!Places.isInitialized()) { Places.initialize(MainActivity.this, getResources().getString(R.string.google_maps_key)); }
// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.getView().setVisibility(set ? VISIBLE : GONE);
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(@NonNull Place place) {
Log.w(TAG, "Place: " + place.getName() + ", " + place.getId());
}
@Override
public void onError(@NonNull Status status) {
Log.e(TAG, "AutocompleteSupportFragment - Ocorreu um erro: " + status);
}
});
}
以下是逻辑猫:
W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
W/libEGL: EGLNativeWindowType 0x6f97da4010 disconnect failed
E/SchedPolicy: set_timerslack_ns write failed: Operation not permitted
W/MainActivity: onActivityResult(95957,-1,Intent { (has extras) })
W/libEGL: EGLNativeWindowType 0x6f753f4010 disconnect failed
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getVisibility()' on a null object reference
W/System.err: at android.view.ViewRootImpl.getHostVisibility(ViewRootImpl.java:1786)
W/System.err: at android.view.ViewRootImpl.handleAppVisibility(ViewRootImpl.java:1422)
W/System.err: at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:4818)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err: at android.os.Looper.loop(Looper.java:214)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7073)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
我在logcat中注意到,这个函数正在返回:
W / MainActivity: onActivityResult (358101, -1, Intent {(has extras)})
之后,我创建了一个新的清洁项目,只为了测试这个资源,并使用相同的代码和返回的函数:
W / MapsActivity: Place: Curitiba, ChIJ3bPNUVPj3JQRCejLuqVrL20 (rigth return in onPlaceSelected)
我认为新的AutocompleteSupportFragment,中有一个bug,因为它不是在onPlaceSelected,中返回调用,而是在onActivityResult.中返回。
相同的错误(W/System.err:)在这两种情况下都会持续,但总是在上面返回之后。
对这件事的原因有什么想法吗?
发布于 2019-06-25 10:36:53
我也通过打电话解决了这个问题
super.onActivityResult(requestCode, resultCode, data);
错误继续出现在日志中,但是现在至少响应是在onPlaceSelected而不是onActivityResult上返回的。
https://stackoverflow.com/questions/56532336
复制相似问题