Android Intent Intent Effect

Source: Internet
Author: User

Intent is divided into two main categories:

(1) dominant (Explicit)

(2) recessive (implicit)

For implicit intent, at some point, an application simply wants to start a component with a certain feature and does not want to be coupled with a particular component. The purpose of this high-level decoupling can be easily achieved by using intent. ( component Start-up between modules )

Intent the destination of the location event:

(1) types (category), such as our common launcher_category, means that this is a class of applications.

(2) type, which is not used in the previous example, represents the type of data, which is an important basis for the target of recessive intent positioning.

(3) component (component), the previous example is SetClass, but you can also use SetComponent to set the intent jump of the front and back two class instances.

(4) additional data (extras), you can attach some information outside the Contenturi, it is the bundle type object.

For dominant Intent:

ComponentName comp = new ComponentName (firstactivity.this, Secondactivity.class);

1 // explicitly specifies the component class to be started, at which point the intent belongs to an explicit intent 2 New Intent (firstactivity.  this, secondactivity. class);

For hidden intent, take a few steps:

(1) Add intent-fileter under activity under the application node in the manifest file to add the action:

<ActivityAndroid:name=". Secondactivity ">      <Intent-filter>          <ActionAndroid:name= "Com.sample.student.query.number" />          <categoryAndroid:name= "Android.intent.category.DEFAULT" />          <DataAndroid:scheme= "Studentnumber" />    </Intent-filter></Activity>     
<ActivityAndroid:name=". Otheractivity ">     <Intent-filter>         <ActionAndroid:name= "Com.sample.student.other"/>         <categoryAndroid:name= "Android.intent.category.DEFAULT"/>         <DataAndroid:scheme= "Student"Android:host= "Www.student.com"Android:port= "8080"/>         <DataAndroid:scheme= "Other"/>         <DataAndroid:mimetype= "text/*" />     </Intent-filter>  </Activity> 

(2)

1 //Action2 Private FinalString studentqueryintent = "Com.sample.student.query.number"; 3 //Data4Uri Studentnumberuri = Uri.parse ("Student:12");5Intent Intent =NewIntent ();6 intent.setaction (studentqueryintent);7 Intent.setdata (Studentnumberuri);8StartActivity (Intent);

Intent Intent = new Intent ();  Intent.setaction ("Com.sample.student.other");  Uri data = Uri.parse ("student://www.student.com:8080");  Intent.setdata (data);  Intent.setdataandtype (data, "text/*");  StartActivity (Intent);

One of the SetData methods:

 1  //  2  //  3  intent.setdata (SetData) is set separately. URI);  4   How To There is a android:mimetype= "text/*" in the <data>, you cannot use intent.setdata at this time, but use Intent.setdataandtype ();  5  Intent.setdataandtype (URI, "Text/plain"  6   Either the Type  7  intent.settype ("Text/plain") are set individually with the Setdataandtype method; 

Multiple data is set, so you can start the activity by matching one.

If you set the <data android:scheme= "student" android:host= "www.student.com" android:path= "/studentnum" android:port= " 8080 "/> must exactly match the Uri data = Uri.parse (" Student://www.student.com:8080/studentnum ") before it can be started.

If <data android:scheme= "student" android:host= "www.student.com"/>, then Uri data = Uri.parse ("student:// Www.student.com:80 "), URI data = Uri.parse (" student://www.student.com:8800 "), URI data = Uri.parse (" student:// Www.student.com ") can be matched.

If only the <data android:scheme= "student"/> is set, then the Uri data = Uri.parse ("test://") can be matched and additional parameters can be added later.

If MimeType is set, then Intent.setdataandtype (data, "text/*") must be used; Start activity.

For an action item in <intent-filter>, you can have multiple matches as long as one of them is matched.

Implicit intent: Intent with no explicitly specified component name is implicit intent. The Android system finds the most appropriate component to handle this intent based on the action (action), category, data (URI, and data type) set in the implicit intent.

Android Intent Intent Effect

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.