using enableAutoManage() in fragment
If you want to use enableAutoManage
then you must make your activity extend FragmentActivity
. The callbacks it makes are required for the automatic management of the GoogleApiClient
to work. So the easiest solution is to add extends FragmentActivity
to your activity. Then your cast would not fail and cause the app to crash at runtime.
The alternate solution is to manage the api client yourself. You would remove the enableAutoManage
line from the builder, and make sure you connect
/disconnect
from the client yourself. The most common place to do this is onStart()
/onStop()
. Something like...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
.addApi(Places.GEO_DATA_API)
.addConnectionCallbacks(this).build();
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
mGoogleApiClient.disconnect();
}
GoogleApiClient.Builder.enableAutoManage in Fragment throws IllegalStateException: Recursive entry to executePendingTransactions
I believe you must use a unique clientId
each time you enable auto manager. From the documentation:
clientId
- A non-negative identifier for this client. At any given time, only one auto-managed client is allowed per id. To reuse an id you must first callstopAutoManage(FragmentActivity)
on the previous client.
Compilation fail at enableAutoManage in GoogleApiclient
I fixed it by adding these two lines in to the GRadle.Property file
android.useAndroidX=true
android.enableJetifier=true
Recursive entry to executePendingTransactions on using GoogleApiClient in Fragment
Instead of calling rebuildGoogleApiClient()
in onViewCreated()
, try calling it in your fragment's onActivityCreated()
method.
See http://developer.android.com/reference/android/app/Fragment.html#Lifecycle for more information on the fragment lifecycle.
If that still doesn't work, you could remove enableAutoManage(...)
and call connect()
and disconnect()
explicitly on the GoogleApiClient
instance.
See https://developers.google.com/places/android/start#connect-client for details.
Does that help?
Related Topics
Android: How Does Gridview Auto_Fit Find the Number of Columns
Camera.Setparameters Failed in Android
How to Make an Fm Radio Application in Android
Android - Communicating Between Two Devices
Android Webview for Facebook Like Button
Getting Results of Nearby Places from User's Location Using Google Maps API in Android
Eclipse Indigo - Cannot Install Android Adt Plugin
Android How to Create Triangle and Rectangle Shape Programmatically
Android: How to Get Gsm Signal Strength for All Available Network Operators
Importing Jar Libraries into Android-Studio
Android Open Camera from Button
Run-As Package 'A.B.C' Is Unknown - Galaxy S4 Jellybean or Android 4.3
Android Ndk: Link Using a Pre-Compiled Static Library
How to Retrieve a List Object from the Firebase in Android
Android - Receiving Long Sms (Multipart)
What Is the Benefit of Using Fragments in Android, Rather Than Views