Solve the problem that after the Android application enters the desktop, click the APP again to throw an exception

android.util.SuperNotCalledException: Activity {com.XXX.XXXActivity} did not call through to super.onCreate()

 

 

Call the following code before the setContentView() call:

  @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate (savedInstanceState);
     
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
        }
        Instance = this;
        setContentView(R.layout.startup_activity);
        tv_version_name = (TextView) findViewById(R.id.tv_version_name);
        checkNewVersion ();
    }

  It should be noted that many people write judgment statements in

Super.onCreate(savedInstanceState); Before, this also caused a crash. 
The judgment statement is used to judge the startup flag of this Activity to see if the application it is in runs from the background to the foreground. If it is, finish() it, and then the system will go to Activity to start the history stack to query the previous activity, so it is restored to the interface where we pressed the home button to go out.
Tested on android 6.0 and android 7.0 normal.
Test machine: Redmi 4A, Redmi 5 plus, Huawei Honor 6

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324936757&siteId=291194637