How to clear stack back to root activity when user leaves application?

后端 未结 2 1727
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 12:40

I have an application with 2 activities, LogonAct and MainAct. LogonAct is a logon activity which I want to force the user to go through each time they return to the application

2条回答
  •  一整个雨季
    2021-02-05 13:15

    You can do following:
    1. set clearTaskOnLaunch = "true" in AndroidManifest, in declaration of main activity
    2. in activity that must close:

    @Override
    public void onBackPressed(){
        moveTaskToBack(true);
    }
    

    so if user presses back - it comes back to homescreen if user launches aplication again - task stack clears and he comes to root main activity

提交回复
热议问题