How can I programmatically close an application?

后端 未结 5 1189
抹茶落季
抹茶落季 2021-01-14 02:08

I am looking for code for a button that completely closes my app.

I tried with some stuff from Google, but my app is still running in the background. I need to close

5条回答
  •  不知归路
    2021-01-14 02:51

    You can close all activities from background and when re-open the app It starts from first activity

    this.finish();
    Intent intent = new Intent(getApplicationContext(), CloseApp.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    

    You can close all activities from background and when re-open the app It starts from paused activity[where you closed] activity

        this.finish();
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    

提交回复
热议问题