views:

161

answers:

2

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.

A: 

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 the Activity

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().

Macarse
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?
Mur Votema
@Mur Votema: ok, then you are willing to do what st0le said.
Macarse
+2  A: 

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.

st0le