An example of Android's intent and Intentfilter application description

Source: Internet
Author: User

Transferred from: http://www.blogjava.net/TiGERTiAN/archive/2010/02/03/311827.html

A lot of people do not understand the intent and intentfilter in the document, I explained here.
Intent literally means goal, purpose. To be popular, some goals need to be achieved, and some actions need to be provided, the classification of these goals, and some of the data needed to achieve these goals. The intent in Android is described by attributes such as action,category and data, and we want to do something (to achieve certain goals), we need to fill in some or all of these parameters, so that Android will help us to do some things automatically.
Intentfilter is born with intent, you have a goal action or result, then those actions and results will have his complete specific requirements, these requirements are intentfilter, can be understood as intent and intentfilter is relative.

<activity android:name=". Testservice"Android:label="@string/app_name"> <intent-filter> <action android:name="Android.intent.action.MAIN"/> <category android:name="Android.intent.category.LAUNCHER"/> <action android:name="Android.intent.action.STORE_REQUEST"></action> <category android:name="Android.intent.category.ALTERNATIVE"/> <category android:name="Android.intent.category.SELECTED_ALTERNATIVE"/> </intent-filter> <intent-filter> <action android:name="Android.intent.action.TIGERTIAN"></action> <category android:name="Android.intent.category.DEFAULT"></category> <data android:scheme="X-id"></data> </intent-filter> <intent-filter> <action Android:name="Android.intent.action.EDIT"></action> <category android:name="Android.intent.category.DEFAULT"></category> <category android:name="Android.intent.category.BROWSABLE"></category></intent-filter> </activity>

The activity above has three filter, the first one for Android system, indicating that the activity can be displayed on the Desktop (launcher). At the same time, alternative shows that this activity can
Become optionmenu for other activity to call directly.
The next two filter is my custom, the second filter can be called directly in other activity in the following way:

Uri uri = uri.parse ("x-id://www.google.com/getdetails?id=123");                 New Intent ();                In.setaction ("Android.intent.action.TIGERTIAN");                In.addcategory (Intent.category_default);                In.setdata (URI);                 // in.setclassname ("Com.tigertian.service", "Com.tigertian.service.TestService");                Testactivity. this. startactivity (in);

In the filter configuration Category_default is indispensable, want to call this service, can not specify class, but other conditions must match (Category_default can not be set, Android default automatically added), With Action,category and data you can invoke the corresponding activity, which is Android help you, of course, if there are more than one match these conditions in the system activity or service,android based on the priority of the call.
The third method of invocation is as follows:

Uri uri = uri.parse ("x-id://www.google.com/getdetails?id=123");                 New Intent ();                In.setaction (intent.action_edit);                In.addcategory (intent.category_browsable);                 // In.setdata (URI);                 // in.setcomponent (New ComponentName ("Com.tigertian.service", "Com.tigertian.service.TestService"));                Testactivity. this. startactivity (in);

Examples of intent and intentfilter applications for Android

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.