Android: launchmode = "singletask" and onnewintent (intent) are two features. Here, we will summarize the experience:
Android: launchmode = "singletask" is configured in mainifest, which ensures that there is always only one activity in the stack, no matter how many times you start it;
Onnewintent (intent) is the parent class method of the override activity. It is called only when you click the Home Key to exit the activity and start a new intent again;
They can be used together to listen to the Home Key (only when a new intent is initiated ).
The Code is as follows:
Manifest. xml
< activity android:name = ".OnNewIntentDemo" android:launchMode = "singleTask" android:label = "@string/app_name" > < intent-filter > < action android:name = "android.intent.action.MAIN" /> < category android:name = "android.intent.category.LAUNCHER" /> </ intent-filter > < intent-filter > < action android:name = "android.intent.action.VIEW" /> < category android:name = "android.intent.category.DEFAULT" /> < data android:mimeType = "video/*" /> </ intent-filter > </ activity >
Code in Activity
@Override protected void onNewIntent(Intent intent) { if (DEBUG) Log.i(TAG, "onNewIntent ~~~~~~~ intent = " +intent); super .onNewIntent(intent); }