Exit/Finish an app/activity - android

前端 未结 12 742
醉梦人生
醉梦人生 2021-02-05 05:04

I\'ve got 4 activities say Act1, Act2, Act3 and Act4. A button in Act1 opens Act2, a button in Act2 opens Act3, a button in A

12条回答
  •  抹茶落季
    2021-02-05 06:07

    I use this method :
    1. Create static activity in the first activity that will close the remaining activity(s).
    2. Then call it in the static method like this, it will close the app from wherever you call it.

    public static Activity activity;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity=this;
    }
    public static void CloseApp(){
        activity.finish();
    } 
    

提交回复
热议问题