The android: launchMode = "singleTask" and onNewIntent (Intent intent) features have been used in recent project development. Here, we will summarize our experiences:
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 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
Java code
- <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
Java code
- @ Override
- Protected void onNewIntent (Intent 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.
From: http://blog.csdn.net/adreamer_bj/archive/2010/12/22/6091414.aspx