Probably it's not a really complicated question, but first of all, I have no idea, what search query should I search for?!
At the beginning of my application I would like to start GPS and if my application will be enden GPS should be closed.
How can I check, if the whole Application (not an Activity) is finished?
Is it enough to use onDestroy-Method for Start-Activity, which will never closed with finish()?
Thank you very much and sorry for a beginner's question.
Mur
UPD
I saw the first answer and I'd like to say once.
I don't mean an ACTIVITY, I mean really the whole APPLICATION (in which many activities exist).
How to check if all application's activities were finished and only in that case stop the service?
Is there posibility for that?
UPD2:
I've tested my solution on a device:
"Is it enough to use onDestroy-Method for Start-Activity, which will never closed with finish()?"
Yes, it was enough.
An Android activity goes through six major lifecycle stages or callbacks. These are: onCreate() , onStart() , onResume() , onPause() , onStop() , and onDestroy() . The system invokes each of these callbacks as an activity enters a new state.
Android Service LifecycleThe lifecycle for a service is similar to that for an activity, but different in a few important details: onCreate() and onStart() differences: Services can be started when a client calls the Context. startService(Intent) method.
A service is started when an application component, such as an activity, starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. 2. Bound. A service is bound when an application component binds to it by calling bindService ...
A Service is an application component that can perform long-running operations in the background. It does not provide a user interface. Once started, a service might continue running for some time, even after the user switches to another application.
Make it so that, each Activity binds (via bindService
) with the Service...When all the activities have been terminated (unbinds implicitly), your Service
will perish. Since the Service will remain alive as long as someone is binding with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With