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> <action Android: Name =" android. intent. action. view "/> <category Android: Name =" android. intent. category. default "/> <data Android: mimetype =" Video/* "/> </intent-filter> </activity>
Activity
@ Override protected void onnewintent (intent) {If (Debug) log. I (TAG, "onnewintent ~~~~~~~ Intent = "+ intent); Super. onnewintent (intent );}
Note: When you press the Home Key to exit and then press the Home key for a long time, the onnewintent will not be accessed because the intent will not be initiated when you enter again.