其他分享
首页 > 其他分享> > android – 在Fragment中使用GoogleApiClient对executePendingTransactions进行递归输入

android – 在Fragment中使用GoogleApiClient对executePendingTransactions进行递归输入

作者:互联网

我正在尝试在我的应用中使用Place Autocomplete API.我有一个主要活动.我有一个片段,它是MainActivity的一部分.在这个Fragment上的OnViewCreated()中.

 private void rebuildGoogleApiClient() {
    // When we build the GoogleApiClient we specify where connected and connection failed
    // callbacks should be returned and which Google APIs our app uses.
    mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
            .enableAutoManage(activity, 0 /* clientId */, this)
            .addConnectionCallbacks(this)
            .addApi(Places.GEO_DATA_API)
            .build();
}

堆栈跟踪:

Caused by: java.lang.IllegalStateException: Recursive entry to executePendingTransactions
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1471)
        at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:488)
        at com.google.android.gms.common.api.zzl.zza(Unknown Source)
        at com.google.android.gms.common.api.GoogleApiClient$Builder.zzkL(Unknown Source)
        at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source)
        at com.app.projectpapri.Fragments.LocationScreen.rebuildGoogleApiClient(LocationScreen.java:69)
        at com.app.projectpapri.Fragments.LocationScreen.onViewCreated(LocationScreen.java:93)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:971)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
        at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
        at com.app.projectpapri.core.BaseActivity.onStart(BaseActivity.java:38)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1243)

任何帮助将不胜感激.

解决方法:

不要在onViewCreated()中调用rebuildGoogleApiClient(),而是尝试在片段的onActivityCreated()方法中调用它.

有关片段生命周期的更多信息,请参见http://developer.android.com/reference/android/app/Fragment.html#Lifecycle.

如果仍然无效,您可以删除enableAutoManage(…)并在GoogleApiClient实例上显式调用connect()和disconnect().

有关详情,请参阅https://developers.google.com/places/android/start#connect-client.

这有帮助吗?

标签:google-api-client,android,android-fragments,google-places-api
来源: https://codeday.me/bug/20190824/1710404.html