Is there some way to prevent the application from closing? Can I do it in the OnDestroy?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With