Stop OS from killing my Process

大憨熊 提交于 2019-12-11 19:35:34

问题


I have an application in which I am calling ACTION_SEND intent from my main activity. Everything works fine but when I return to my main activity from ACTION_SEND intent then main activity starts its execution from onCreate() method but I want it to be started from onRestart() method. I think its bcz a OS kills my activity to free up space. So is there any way rather than using Service So that I can stop OS from killing my activity ?


回答1:


I think its bcz a OS kills my activity to free up space

Possibly. You might be doing something yourself to destroy your activity (e.g., calling finish() after calling startActivity() for your ACTION_SEND Intent).

So is there any way rather than using Service So that I can stop OS from killing my activity ?

No. Even a service may not help. Your process can be terminated at any time, for any reason, including the user deciding to terminate it via a task manager or the recent-tasks list. Also, if the user rotates the screen or causes another configuration change while in whatever app they started via ACTION_SEND, your activity that called startActivity() with ACTION_SEND will be recreated due to the configuration change.

You cannot assume that onRestart() will be called. In general, I consider onRestart() to be a code smell for just this reason.



来源:https://stackoverflow.com/questions/23183672/stop-os-from-killing-my-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!