views:

27

answers:

1

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 thought 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!

A: 

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

Computerish
Thanks for responding. The description of that flag says that whenever you go to the home screen or switch tasks, all other activities but the root are killed. What I was hoping to achieve was to kill my whole app, but only if the OS kills one of my activities for memory related reasons. In normal situations, no need to do anything, but rather than kill one related activity and not the others, I'd rather it just shut me down. The iPhone, Windows Mobile, etc all behave in this manner by default. It works well in my situation but unfortunately not sure if it's possible.
Dave Haupert