Which method is called when the application is closed

I read all about the activity life cycle and its methods.

I still could not find the answer: When I close my application, from the "open applications" menu (in galaxy4 it takes a long press on the "home" button, in nexus5 it is the correct button ...) which method is called? if there?

In other words, my activity launches the service. I want to shut down the service if the application (action) closes. (onDestory is not reliable at all, as said many times here before)

Thanks in advance!

+6
source share
3 answers

onPause () is the only method that is always called. From the onPause () state, the Android OS can kill this application for many reasons, bypassing onStop and onDestroy. I do not think that we can safely control this behavior of unexpected completion. The service may periodically check the status of the application.

+4
source

You will pass onPause() , then onStop() . On pre-Honeycomb devices (API 11), your application may be killed at any time after onPause() returns. No more methods are called, period. Post-Honeycomb, you will at least get onStop() .

+1
source

Find with life cycle activity, one sugestion: http://developer.android.com/training/basics/activity-lifecycle/stopping.html

The system calls onPause (), after onStop () and last onDestroy (). You must analyze the best form to include your method. Pay attention at this moment.

0
source

Source: https://habr.com/ru/post/972252/


All Articles