Close application and launch home screen on Android

后端 未结 21 2032
我在风中等你
我在风中等你 2020-11-22 07:33

I have two different activities. The first launches the second one. In the second activity, I call System.exit(0) in order to force the application to close, bu

21条回答
  •  [愿得一人]
    2020-11-22 08:04

    This is what I did to close the application: In my application I have a base activity class, I added a static flag called "applicationShutDown". When I need to close the application I set it to true.

    In the base activity onCreate and onResume after calling the super calls I test this flag. If the "applicationShutDown" is true I call finish on the current Activity.

    This worked for me:

    protected void onResume() {
        super.onResume();
        if(BaseActivity.shutDownApp)
        {
            finish();
            return;
    
        }}
    

提交回复
热议问题