Listen to the 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> <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.

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.