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

1 votes
276 views
Harsh kumar srivastava asked 10-Jan-2018 in Technology by Harsh kumar srivastava
edited 10-Jan-2018 by Harsh kumar-srivastava

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 votes
Prateek sharma answered 10-Jan-2018 by Prateek sharma

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().