I read all about the activity lifecycle and it's methods.
I still couldt find an answer: When I close my app, from the "open apps" menu (in galaxy4 it's a long press on the home button, in nexus5 it's the right button ...) what method is being called? if any?
In other words, my activity is launching a service. I want to terminate the service if the app (activity) is being closed. (onDestory is not reliable at all as said many times here before)
Thanks in advance!
A Service method onTaskRemoved will be called when we remove app from recent items.
The onPause() and onResume() methods are called when the application is brought to the background and into the foreground again.
OnDestroy. OnDestroy is the final method that is called on an Activity instance before it's destroyed and completely removed from memory. In extreme situations Android may kill the application process that is hosting the Activity, which will result in OnDestroy not being invoked.
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
onPause() is the only method that is called always. From onPause() state Android OS can kill this app for many reasons bypassing onStop and onDestroy. I don't think we can control this behavior of unexpected termination smoothly. Service can check for the state of the application periodically.
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