How to Control Android back stack

后端 未结 4 495
挽巷
挽巷 2020-12-09 23:02

Lets say I have

A->B->C->D->E

In android back stack. I want to be able to get back to one of the following:

A->B->C
A->B
A
<         


        
4条回答
  •  伪装坚强ぢ
    2020-12-09 23:44

    Actually , to go "up" to the activity of your choice, you should use the "up" navigation as used on the action bar:

    /** used to handle the "up" button on the action bar, to go to the defined top activity as written on the manifest */
    public static void goUpToTopActivity(final Activity currentActivity) {
        final Intent intent = NavUtils.getParentActivityIntent(currentActivity);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        NavUtils.navigateUpTo(currentActivity, intent);
    }
    

    in order to use it, you must set on the manifest to which activity this function should use (or you could of course set it yourself by changing the code) :

    if you use actionBarSherlock, for each activity that you wish to let to go up, use:

    
    

    if you use the android framework (if your minSdk version is API 16 and above), use the "parentActivityName" attribute.

提交回复
热议问题