Recursive write in executePendingTransactions when using GoogleApiClient in fragment
I am trying to use the Place Autocomplete API in my application. I have a chief Activity
. I have Fragment
that part MainActivity
. In OnViewCreated()
on this Fragment
.
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();
}
StackTrace:
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)
Any help would be appreciated.
source to share
Instead of calling rebuildGoogleApiClient()
in, onViewCreated()
try calling it in a fragment method onActivityCreated()
.
See http://developer.android.com/reference/android/app/Fragment.html#Lifecycle for details on Fragment Lifecycle .
If that still doesn't work, you can delete enableAutoManage(...)
and call connect()
and disconnect()
explicitly on the instance GoogleApiClient
.
See https://developers.google.com/places/android/start#connect-client for details .
Does it help?
source to share
Worked for me:
public class TestActivity extends Fragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(Places.GEO_DATA_API)
.build();
}
@Override
public void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
public void onStop() {
super.onStop();
mGoogleApiClient.disconnect();
}
}
source to share