开发者

How to stop an application if any of the activities were killed by the OS

I have an application with many forms implemented as separate activities. The form variables are dynamically built based on a database, and there are a ton of variables in the C++ side of the application (accessed via JNI). I don't see how saving out all of this data to persistent storage each time the onPause() or the onSaveInstanceState() of one of these many activities goes into the background is a smart use of processor time. And I don't see how even if I save the local variables for each activity during that time I'd be able to restore a single activity within the context of all the others.

I have set up a service that auto saves the files when I detect that the app has gone into the background. (I set a time stamp when onPause() is called in any activity and then clear the time stamp when onResume() is called on any other activity. If the time elapsed is more than a few seconds, I know I'm not the top activity any longer and the service saves the files).

What I'd like to do is continue on as normal unless the OS kills one of my activities. Since we don't always get notified of this, I th开发者_开发知识库ought it would be nice if there were a way to tell the OS that I'd rather you kill the whole app than just one activity.

Thanks in advance!


Setting clearTaskOnLaunch="true" in the manifest's <activity> tag for the root Activity combined with settingnoHistory="true"` in all the activities's tag should do what you are looking for.

http://developer.android.com/guide/topics/manifest/activity-element.html#clear http://developer.android.com/guide/topics/manifest/activity-element.html#nohist

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜