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.
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.
In this particular case what you need to do is:
- Create an
Activity
to show information to the user. - Create a
Service
that will run on background and will send the updates to theActivity
There are lot's of examples of what you are trying to do, but basically you can start the Service
on the onStart()
method of your Activity
and ending the service on the onDestroy()
.
精彩评论