location-samples icon indicating copy to clipboard operation
location-samples copied to clipboard

More than one activities require API client connection

Open katie1006 opened this issue 9 years ago • 2 comments

Hi,

As recommended by Google, I was trying to connect to API client in onStart() and disconnect in onStop. However, the onStart() in Activity2 is called before the onStop() in Activity1, which causes the API client to be disconnected in Activity2.

I thought about simply not disconnecting API client in Activity1, but I'm worrying that if user kills the app in Activity1, would the API remain connected and end up causing memory issue or app crashing?

Is there a recommended way to resolve this issue?

katie1006 avatar Feb 05 '17 16:02 katie1006

"the onStart() in Activity2 is called before the onStop() in Activity1". Can you explain how this happens? I am a little confused.

shailen avatar Oct 17 '17 06:10 shailen

I was referring to this page. Sorry, should have mentioned my question is regarding activity navigation. https://developer.android.com/guide/components/activities/activity-lifecycle.html#soafa

Should I only connect API client when needed instead of keeping it alive with the activity? Then what if I require continuous GPS updates in two different activities?

katie1006 avatar Oct 17 '17 15:10 katie1006