How to close all the activities of my application?

后端 未结 4 1973
天涯浪人
天涯浪人 2020-11-29 04:23

I\'ve got an application with several activities, for example:

Activity 1 --> Activity 2 --> Activity 3 --> Activity 4

And I would like to close all the acti

4条回答
  •  孤街浪徒
    2020-11-29 04:48

    Open up AndroidManifest.xml and find the activity that you would like to return to and add the following attribute

    android:launchMode="singleTask"
    

    For example, HomeActivity class might have this in android manifest

    
    

    At any point, you can close all activities on top of this one by using startActivity the standard way, for example

    startActivity(new Intent(this, HomeActivity.class));
    

    If you normally pass extras to the intent, there's no need to do this as it will come back in whatever state it was before, and it's even accompanied by an animation like hitting the back button.

提交回复
热议问题