Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Android Service outlive Application object?

So, the question is pretty self-explanatory. Can custom Application object (the one I declare in AndroidManifest.xml) be destroyed earlier than the launched Service, provided that Service is not launched in another process?

My intuition says it's not possible, since we can access Application object in Service by calling getApplication(), plus I've not seen anything like this in documentation, but Android is full of unexpected funny behaviors.

like image 507
Alexander Woodblock Avatar asked Jan 24 '16 17:01

Alexander Woodblock


People also ask

How do I keep my service alive Android?

But in order to keep a service alive like playing a song in a background. You'll need to supply a Notification to the method which is displayed in the Notifications Bar in the Ongoing section. In this way the app will keep alive in background without any interuption.

How do I stop an Android application from closing?

In android, by pressing a back button or home button. So put an event key listener for back & home button and terminate the service.

How do I stop programmatically running in the background Android?

stopSelf() is used to always stop the current service. stopSelf(int startId) is also used to stop the current service, but only if startId was the ID specified the last time the service was started. stopService(Intent service) is used to stop services, but from outside the service to be stopped.

What is an Android service?

An Android service is a component that is designed to do some work without a user interface. A service might download a file, play music, or apply a filter to an image. Services can also be used for interprocess communication (IPC) between Android applications.


1 Answers

Can custom Application object (the one I declare in AndroidManifest.xml) be destroyed earlier than the launched Service, provided that Service is not launched in another process?

Each process gets its own Application object, and that object lives as long as the process does. Hence, any component (e.g., a Service) cannot outlive the Application from its own process.

like image 51
CommonsWare Avatar answered Nov 15 '22 15:11

CommonsWare