问题
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