Android moving back to first activity on button click

后端 未结 6 2200
情歌与酒
情歌与酒 2020-12-03 07:14

I am writing a application where I am dealing with 4 activities, let\'s say A, B, C & D. Activity A invokes B, B invokes C, C invokes D. On each of the activity, I have

6条回答
  •  余生分开走
    2020-12-03 07:35

    The only problem i see using android:launchMode="singleTask" is whenever you minimize app and start app by pressing app icon again then app start from scratch and doesn't acquire its state. so i have opted to use

    intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );
    

    which will keep only one instance and clear all activities on top of that.

    Intent intent = new Intent( context, MyActivity.class );
    intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );
    current_activity.startActivity( intent );
    

提交回复
热议问题