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.
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.
In android, by pressing a back button or home button. So put an event key listener for back & home button and terminate the service.
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.
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.
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.
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