Issue
I seem to have hit a limitation with the lifecycle of my application.
I have an activity which uses a Google API. At some point I make a connection to that API and it attempts to connect. On the first attempt it fails to connect because we haven't selected an account and authorised it. As a result the Google SDK launches connectionResult.startResolutionForResult - a method which basically just shows an account selection DialogFragment.
When the SDK method is invoked it triggers onPause on my Activity.
This is a problem because my onPause method calls disconnect() on the Google API (as is good practice). The problem then being that I do want to disconnect when closing the activity/application but I don't want to start disconnecting while I'm resolving the account problem (in the background I am reattempting the connection which will be successful as soon as the user picks their Google account, there doesn't seem to be a callback to detect when it happens)
What's the piece of this puzzle that I am missing?
Solution
Ideal scenario would be to move disconnect() to onStop()
According to the Activity lifecycle documentation onStop() will be called except the low memory situations (which is anyway not idea situation). I believe you should be fine.
But in any case if you want this disconnect() method to be called in low memory scenario then probably you should keep this method in onPause() and take a boolean flag. Set it to true when the dialog is opened. When this boolean flag is true don't disconnect. Don't forget to set it to false otherwise you won't disconnect ever
These are the two solutions I could think of. Hope it helps.
Answered By - Rohit5k2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.