Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android application lifecycle and service

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.

like image 920
Tima Avatar asked Sep 17 '10 09:09

Tima


People also ask

What is the Android application lifecycle?

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.

Is service lifecycle same as activity lifecycle?

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.

What is service explain life cycle of service in Android?

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

What is a service in Android application?

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.


1 Answers

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.

like image 158
st0le Avatar answered Sep 27 '22 16:09

st0le