BUG record

1. Return to the desktop and start again. The Splash page is displayed

Yesterday, I sent a new test package to the test, and the result returned a bug to me: after the APP had logged in, I clicked back to the desktop and then clicked the application icon again, the flash screen page started again, and then jumped to the login page (no persistent login was made). I have never met this situation before. I have searched the Internet and found the answer. I hereby record it.

reference

Android Bug analysis series: third-party platform after the installation of app startup, the home button back to the desktop after clicking app startup will start again the cause of the Bug analysis of the entry class

Bug reason

The intent started by the third-party app was inconsistent with the intent started by the desktop. As a result, the entry of the application was enabled again

The solution

// Avoid activities that re-instantiate the entry class after starting the application from the desktop
if (!this.isTaskRoot()) {
    Intent intent = getIntent();
    if(intent ! =null) {
        String action = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
            finish();
            return; }}}Copy the code

Matters needing attention

Logically, splash does most of the initialization and releases these objects in the onDestroy method. To fix this bug, the above code is executed immediately in onCreate, so some objects have not yet been initialized, so onDestroy releases the object with a non-null check.