Reputation: 101
So, I have a bunch of activities. The flow is as follows:
Main Activity: I connect to Google Plus account here, then call Show Logs, to get data from Google account.
I also have About and Setting activities. Now if I go to About then come back to Logs, Android throws error that GoogleApiClient is not connected. So should I again call the MainActivity for connecting else should I move all of the connection code to Common or Base Activity.
I am sorry if I am not clear enough.
Upvotes: 1
Views: 69
Reputation: 1560
If the GoogleApiClient is instantiated in the Main activity, once you leave that activity it will disconnect.
For your purposes you can try having multiple instances of the GoogleApiClient across your activities (might be inefficient) but Google's interface will not require the user to sign in multiple times for each activity. Each instance will access the same state. You can check this post for more info Access google plus client from multiple activities
Or have try to implement the connection in an AsyncTask that will keep running in the background. Have a look at this link http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html
Upvotes: 2