Restarting Android application after process is killed

前端 未结 3 1899
广开言路
广开言路 2021-02-04 07:26

When my application is idle, Android kills the process. If user reopens the application after some time, only the top Activity is created - this is a problem for me because the

3条回答
  •  野性不改
    2021-02-04 08:03

    Just identify that your Application is being launched after it was previously destroyed by Android, you could do this by keeping a variable in a custom Application class, and set it to true after your applicaiton is initialized. So when the applicaction is re-launched, this flag is false, and then just make an Intent to launch your main Activity specifying FLAG_ACTIVITY_CLEAR_TOP :

    Intent reLaunchMain=new Intent(this,MainActivity.class);
    reLaunchMain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(reLaunchMain);
    

提交回复
热议问题