Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of onDestroy( ) in Android

If Java provides Garbage Collection, then what is the need of onDestroy() in Activity Lifecycle?

like image 243
Varun Chaudhary Avatar asked Dec 18 '12 06:12

Varun Chaudhary


People also ask

What happens when onDestroy is called?

If onDestroy() is called as the result of a configuration change, the system immediately creates a new activity instance and then calls onCreate( ) on that new instance in the new configuration.

What is the difference between onStop and onDestroy?

Once onStop() is called then onRestart() can be called. onDestroy() is last in the order after onStop(). onDestory() is called just before an activity is destroyed and after that it is gone it is not possible to resurrect this.

When onDestroy () is called before onPause () and onStop () in an Android application?

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.

Does onDestroy finish call?

Third, finish() does not call onDestroy() .


1 Answers

onDestroy: The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it), or because the system is temporarily destroying this instance of the activity to save space.

Here is an example......

 public void onDestroy() {
              
   super.onDestroy();

 }
like image 92
sam786 Avatar answered Oct 05 '22 23:10

sam786