Intent in-depth learning

Source: Internet
Author: User

Start-up activities there is a startactivityforresult, this need to master.

Start the service and always use explicit intent.

The intent filter represents the type of intent that this component may want to accept. Also say, the intention has type?? What do you mean, if you do not specify intent filter, only the boot is displayed.

Create an intent:

Component name: In explicit, express start class, use Setcomponent,setclass,setclassname to set, so seen SetClass set,

If not added, it is implicit intent.

Action: Actions to be performed, such as Action_view action_send, can generally be initiated as a function or application, typically defined in <intent-filter>

Data: I saw it in the sunshine content provider,

Intent (Getapplicationcontext ()detailactivity.  Class)        . SetData (Itemuir);  startactivity (Intent);

In Detailactivity's OnCreate: Getintent (). GetData () Gets the saved URI that is used to query the specific information.

@Overrideprotected voidonCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);    Setcontentview (r.layout.Activity_detail);if(Savedinstancestate = =NULL) {Bundle arguments =NewBundle ();        Arguments.putparcelable (detailfragment.Detail_uri, Getintent (). GetData ());        Detailfragment fragment =NewDetailfragment ();        Fragment.setarguments (arguments);        Getsupportfragmentmanager (). BeginTransaction (). Add (r.id.Weather_detail_container, Fragment). Commit ();    }}

Category: Defined together with action in <intent-filter>, the combination appears.

Extras: It is also common to pass on additional information.

Flags: Useless or


The general definition, the most is this: or the simplest, even <intent-filter> are not, are relatively simple, but it is not easy to use it.

<activityAndroid: Name=". App. Isolatedservice$controller "        Android: label="@string/activity_isolated_service_controller"        Android: launchmode="Singletop"        Android: enabled="@bool/atleastjellybean"><intent-filter><actionAndroid: Name="Android.intent.action.MAIN"/><categoryAndroid: Name="Android.intent.category.SAMPLE_CODE"/></intent-filter></activity>

Use implicit intent to note:

To ensure that there is a response, first test:

//Create The text message with a stringIntentsendintent= New Intent();sendintent.setaction(Intent.Action_send);sendintent.PutExtra(Intent.Extra_text,TextMessage);sendintent.SetType("Text/plain");//Verify that the intent would resolve to an activityif (sendintent.resolveactivity(Getpackagemanager()) != NULL) {startactivity(sendintent);}

Use Createchooser, display the title, let the user choose

Intentsendintent= New Intent(Intent.Action_send);...//Always use the string resources for UI text.//This says something like "Share this photo with"Stringtitle=getresources().getString(R.string.Chooser_title);//Create Intent to show the Chooser dialogIntentChooser= Intent.Createchooser(sendintent,title);//Verify The original intent would resolve to at least one activityif (sendintent.resolveactivity(Getpackagemanager()) != NULL) {startactivity(Chooser);}

Intent-filer, keep watching tomorrow.


Intent in-depth learning

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.