The last callback in the lifecycle of an activity is onDestroy()...

Asked 10-Jan-2018
Updated 10-Jan-2018
Viewed 783 times

1

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 system memory. Usually, the system will call onPause() and onStop() before calling onDestroy(). Describe a scenario, though, where onPause() and onStop() would not be invoked.


1 Answer


1

to understand this scenario let's look at the example - 

@Override
public void onCreate(Bundle savedInstanceState){
//calling super class
 super.onCreate(savedInstanceState);
//some work here
//calling finish()
finish();
}
@Override
public void onResume(){
//you need to tell the super class about this invocation, so
super.onResume();
//do your work
}
@Override
public void onPause(){
//you need to tell the super class about this invocation, so
super. onPause();
//do your work
}
@Override
public void onStop(){
//you need to tell the super class about this invocation, so
super. onStop();
}
@Override
public void onDestroy(){
//you need to tell the super class about this invocation, so
super. onDestroy ();
}

when the user calls the finish() method this will directly trigger the onDestroy() method without going through onPause() and onStop().