Android: What can we do to ensure that onDestroy() gets called? : I have a line of code that I should call after my activity is destroyed, so I override onDestroy() method and I call it inside. like this:

       @override
       public void onDestroy(){

         //my code here
      
         super.onDestroy()  
 
       }

 

Now I noticed that the this line of code is not always executed when my activity finishes.

I read about this and some said don't depend on onDestroy() method to call something.

My question is I need to call the code from onDestroy() and I want it to always work. Any thoughts on this? And why onDestroy() is found in the first place if we cant depend on it to execute?

Thanks.