Reputation: 1471
I have an App where I need current GPS location by one or many Activities, In an attempt to reduce the waiting time for the user, I am trying to start the GPS LocationListener at the App launch. I want when my App exits (Go to Home screen) from any of the activity, GPS listener should be stop. I am having several activities and any activity can use GPS but due to my App flow we are not sure from which activity user would exit So I want to maintain some global state of the GPS for Start and Stop. Basically binding the Start and Stop with App Start and Stop.
I am looking for some concrete solution for this, Any pointers would be great..Please guide!!
Upvotes: 0
Views: 607
Reputation: 980
Try to use denis.solonenko idea to handle that. If you still want to keep your own way you could try using the startActivityForResult()
function to get information when a child activity returns to your main activity.
Upvotes: 0
Reputation: 11775
That doesn't sound like a good idea. You should manage GPS listeners on Activity level - attach them in onResume
and detach in onPause
. I believe the problem is that you have many Activities and you want to do the same stuff in every of them. Just create a base abstract Activity class to manage GPS connect/disconnect and extend every activity from this class.
Upvotes: 2