androidandroid-activitylifecycleactivitygroup

Android Activity-Lifecycle... how to avoid onDestroy()?


I have an App, which uses an ActicityGroup to have a stack of Activitys. If I start a new Activity, I do this as Child of my ActivityGroup. Lets assume I'm in my starting Activity (1), and I start a new one(2), so here is what's getting called:

(1): onPause()

(2): onCreate(), onStart(), onResume()

until here, everything as aspected. if I press my BackButton the stack is as following:

(2): onPause(), onStop(), onDestroy()

(1): onStop(), onDestroy() [sic]

(1): onCreate(), onStart(), onResume()

I see no reason,first why (1) should perform onStop, and onDestroy(), to reCreate again, and second why onRestart never gets called on (1).

Has anyone a Reason for this behavior? Can I 'cancel' calls to onStop() or onDestroy() somehow? any idea apreciated


Solution

  • Try using FLAG_ACTIVITY_SINGLE_TOP when starting child activity, like:

        Window window = getLocalActivityManager().startActivity(id,
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
    

    More info here:

    http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_SINGLE_TOP