Search code examples
androidandroid-intentchildactivity

TabGroupActivity startChildActivity - pause currentActivity


Extending TabGroupActivity, when I start a new childActivity:

public void startChildActivity(String Id, Intent intent) {
    Window window = getLocalActivityManager().startActivity(Id,
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
    if (window != null) {
        activityIdList.add(Id);
        setContentView(window.getDecorView());
    }
}

How can I put the current activity into the pause state?

Because after I start a child activity in this way, when I restart it, then the on create method is run. How can I avoid this?

Found one solution is to use another flag:

Intent.FLAG_ACTIVITY_REORDER_TO_FRONT

but not sure if it is the best solution

P.P.S Another solution is to add an boolean intent to the startChildActivity method:

public void startChildActivity(String Id, Intent intent) {
    intent.addExtra("resume", true);
    Window window = getLocalActivityManager().startActivity(Id,
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
    if (window != null) {
        activityIdList.add(Id);
        setContentView(window.getDecorView());
    }
}

and then retrieve it from the child activity and check if the activity is restarted or not


Solution

  • Try putting this in activity tag in the manifest file

    android:launchMode="singleTask"
    

    It should look something like this

    <activity android:name=".dashboard.DashboardActivity" android:screenOrientation="portrait"
            android:launchMode="singleTask"/>