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
View plaincopy to clipboardprint?
<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>
<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>
Activity
View plaincopy to clipboardprint?
@ Override
Protected void onnewintent (intent ){
If (Debug) log. I (TAG, "onnewintent ~~~~~~~ Intent = "+ intent );
Super. onnewintent (intent );
}
@ 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.
Note:
In the R & D project, because the player is used as singleinstance, you need to use onnewintent to call it again.