Home > DeveloperSection > Interviews > The last callback in the lifecycle of an activity is onDestroy(). The system calls this method on your activity as the final signal that your activity instance is being completely removed from the sys

Posted on    August-02-2015 11:39 PM

 Android Android  Android Activity 
Ratings:
 1 Answer(s)
  439  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    August-02-2015 11:39 PM

onPause() and onStop() will not be invoked if finish() is called from within the onCreate() method. This might occur, for example, if you detect an error during onCreate() and call finish() as a result. In such a case, though, any cleanup you expected to be done in onPause() and onStop() will not be executed.

Best practice in Android development is to have the activity perform most cleanup during onPause() and onStop(). However, if the activity includes background threads that are created during onCreate(), or other long-running resources that could potentially leak memory if not properly closed, you should kill them during onDestroy().

Don't want to miss updates? Please click the below button!

Follow MindStick