Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent an Android application from getting closed/stopped

Is there some way to prevent the application from closing? Can I do it in the OnDestroy?

like image 269
Sebosin Avatar asked Feb 17 '26 01:02

Sebosin


2 Answers

If your question is where you can prevent your application from being closed that is not possible. The system has the right to close when it runs on low resources or when the user wants to - through a task killer or the incorporated system in ICS.

OnDestroy just notifies you about that, you can't "revive" the application there.

like image 105
azertiti Avatar answered Feb 19 '26 15:02

azertiti


You cannot prevent the application from closing as the kernel may force it to shut down if the device becomes low on resources. Normally, when the system is low on resources, the kernel will inform the application that it wishes to close it. Allowing the application to execute its onDestroy method and then close.

Your onDestroymethod can be useful for saving state. Here's a skeleton example:

protected void onDestroy() {        
   super.onDestroy();
   //state is saved here.
}

However, it's worth remembering that you're not guaranteed that onDestroy() will execute. The kernel may or may not give it time to do so. You should check out the Activity Life Cycle for further information

like image 34
Aidanc Avatar answered Feb 19 '26 15:02

Aidanc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!