Android has a better exit application scheme than system.exit(0) or Process.killProcess (recommended)

After the system.exit(0) or Process.killProcess call is found during the development process, if there is still activity, it will cause many problems such as program killing and restarting.
First add the [boolean] value ifexit to the application

public class myapplication extends Application {
    public [static] boolean ifexit;
}

Then in our BaseActivity, which is the parent class of all our activities

@Override

protected void onRestart() {

super.onRestart();

if(myapplication.ifexit==true){

finish();

}

}

myapplication.ifexit = false;

private boolean isExit;

However, the app can be implemented using acidvy + a large number of fragments, and the main activity can be set to android:launchMode=”singleTask” mode in AndroidMainfest.xml. Then after opening the multi-level page, when returning to the activity, you only need to return to this page, The previous multi-level pages are automatically closed.

Farewell! !

Leave a Comment

Your email address will not be published. Required fields are marked *