How to close activity and go back to previous activity in android

后端 未结 18 1858
孤独总比滥情好
孤独总比滥情好 2020-12-07 08:19

I have a main activity, that when I click on a button, starts a new activity, i used the following code to do so:

Intent intent = new Intent(this, SettingsAc         


        
18条回答
  •  旧时难觅i
    2020-12-07 08:48

    You have to use this in your MainActivity

     Intent intent = new Intent(context , yourActivity);
    
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                context.startActivity(intent);
    

    The flag will start multiple tasks that will keep your MainActivity, when you call finish it will kill the other activity and get you back to the MainActivity

提交回复
热议问题