When is the onNewIntent method called?

Today, Saturday, a good day to code at home, I wrote a demo apk to verify when the onNewIntent method is called.

Situation 1:

    // 启动自己
    public void startSelf(View view) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);
    }

Situation 2:

The first step is to add the singleTask attribute where the activity is known in AndroidManifest.xml:

<activity 
          android:name=".MainActivity"
          android:launchMode="singleTask">

The second step, when starting, do not set any flag, the code is as follows:

    public void startSelf(View view) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }

Situation 3:

The first step is to add the singleTop attribute where the activity is known in AndroidManifest.xml:

<activity 
            android:name=".MainActivity"
            android:launchMode="singleTop">

In the second step, no flag is set at startup, and the code is the same as in case 2.


Situation 4:

The first step is to add the singleInstance attribute where the activity is known in AndroidManifest.xml:

<activity 
            android:name=".MainActivity"
            android:launchMode="singleInstance">

In the second step, no flag is set at startup, and the code is the same as in case 2.

I don’t know if there is any other situation, please leave a message.

Guess you like

Origin blog.csdn.net/Xia_Leon/article/details/83036745