本文介绍了阻止操作系统杀死我的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,在其中我要从main activity调用ACTION_SEND意图.一切正常,但是当我从ACTION_SEND目的返回我的主要活动时,main activityonCreate()方法开始执行,但是我希望从onRestart()方法开始.我认为它的OS会杀死我的活动以释放空间.那么有什么方法可以使用,而不是使用Service来阻止操作系统终止我的活动?

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 ?

推荐答案

可能.您可能自己在做些事情来破坏自己的活动(例如,在为ACTION_SEND Intent调用startActivity()之后,调用finish()).

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

不.甚至服务也可能无济于事.您可以随时以任何理由终止您的进程,包括用户决定通过任务管理器或近期任务"列表终止该过程.另外,如果用户在通过ACTION_SEND启动的任何应用中旋转屏幕或引起其他配置更改,由于配置更改,将重新创建名为startActivity()ACTION_SEND的活动.

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.

您不能假定将调用onRestart().通常,出于这个原因,我认为onRestart()是代码气味.

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

这篇关于阻止操作系统杀死我的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 07:21