Android listening Home Key (Android: launchmode = "singletask" and onnewintent (intent) Usage

Source: Internet
Author: User

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);   }  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.