1

I have a main activity from which the user starts several activities with startActivityForResult . This might be an external application like the xing barcode scanner or a internel activity like a mapview or calendar ect.

The Problem is, by executing startActivityForResult my main activity is paused and might be terminated by the android system. Somtimes, when the user stay a long time in a started activity this happens and after closing the new activity the main activity is destroyed and the OnActivityResult Listener is not called.

Is there a way to tell the system "Do not destroy this paused activity" ?

edit:

The Problem is a little bit more complicated, i fear i've made many mistakes in the whole achitecture of my app. I will try to explain what i've done:

I have a main activity (extends TabActivity) and a final public class GlobalVars in GlobalVars is store lots of Variables or Classes, which are used by all activities of the project eg. :

public static boolean system_initialized = false;
public static boolean system_Onforeground = true;

in the main.class OnCreate Method, i set system_initialized to true in the OnResume method i set Onforeground = true , in onPause is set Onforeground = false and in OnDestroy is set initialized = false

if I start the app system_initialized and Onforeground will be true, if i start a ActivityforResult initialized will stay true, but Onforeground will be set to false.

Now i have a BroatcastReceiver wich starts android.intent.action.BOOT_COMPLETED and initialise a Alamrmmanager with a Service as pendingIntent.

Now I use the service to check every minute if i have to do something in the main activity. If a action occured, the services checks if system_initialized = true (in GlobalVars) if not, the service starts the app, otherwise the service use a handler (in GlobalVars) to call a Runnable in the main activity.

This works well, if the main Activity is running, the runnable will be executed and something happens, if the user has started a ActivityforResult the service realised that the main activity is not onForeground and do something in the background. But if the main activity is destroyed, the service will restart the main activity and i don't want that ^^

I know, quite strange, but i dont know how to realise the things i need in a other way...

4

1 回答 1

1

但是当你回到你的活动时,它会被重新创建。
您需要做的就是使用onSaved实例和其他方式保存您的活动状态。

您还可以将检查放入您onLowMemory获得的应用回调中。

请点击 SO 上的链接。
这可能会有所帮助。

处理 DVM 杀死你的活动

于 2012-05-30T09:39:49.290 回答