Start Activity clearing top in Android

后端 未结 2 1515
鱼传尺愫
鱼传尺愫 2021-01-16 01:19

I have the following Activities in my stack:

A , B , C, D 

I want to relaunch B in order to get this stack:

A , B\'
         


        
2条回答
  •  别那么骄傲
    2021-01-16 02:03

    here when you use this code the its take you on activity B. in B you Press backbutton the its take you on A.

    Intent fromDtoB = new Intent(this,B.class);
    fromDtoB.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(fromDtoB);
    

    FLAG_ACTIVITY_CLEAR_TASK: If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.

    FLAG_ACTIVITY_CLEAR_TOP: If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

提交回复
热议问题