Android intent. action_chooser and intent. action_pick_activity

Source: Internet
Author: User

1. Intent. action_chooser = "android. Intent. Action. chooser" indicates an activity selector.

Intent provides a static createchooser method, allowing us to easily create such an intent. For specific usage examples, refer to the startwallpaper function of launcher. Java in the launcher application:

Private voidStartwallpaper (){

Closeallapps (True);

FinalIntent pickwallpaper =NewIntent (intent.Action_set_wallpaper);

Intent chooser = intent.Createchooser(Pickwallpaper,

Gettext (R. String.Chooser_wallpaper));

 

Startactivityforresult (chooser,Request_pick_wallpaper);

}

Here we want to find all intent processing capabilities.Action_set_wallpaperThe requested activity. Its string is Android. Intent. Action. set_wallpaper. After searching by eclipse, the androidmanifest. xml file of the following application finds the activity that can process this request:

Packages/apps/Gallery

Packages/apps/launcher2

Packages/wallpapers/livepicker

Therefore, after you click wallpaper on the home page, you can list these applications in a dialog box, as shown in.



 

In, When you click any list item, the corresponding activity is activated. The user's wallpaper setting operation is completed in the newly started activity. For example, if the user clicks the "photo" item, the app will be displayed in the gallery application. For more information, see.



 

2. Introduction to intent. action_pick_activity and their differences

Intent. action_pick_activity = "android. Intent. Action. pick_activity ".

At first glance, I cannot see the difference between it and intent. action_chooser. In order to clarify this point, I made a special experiment and changed the intent action of the wallpaper above to intent. action_pick_activity. The running interface is shown in.



From the interface, the expression of intent. action_chooser is basically the same as that of intent. action_chooser, but the selected activity is not started after you click it. I quickly found the cause from the android source code.

The processing of intent. action_pick_activity action is located in the settings application, as shown in the following XML.

<Activity Android: Name ="Activitypicker"

Android: Label ="@ String/activity_picker_label"

Android: theme ="@ * Android: style/theme. Dialog. Alert"

Android: finishonclosesystemdialogs ="True">

<Intent-filter>

<Action Android: Name ="Android. Intent. Action. pick_activity"/>

<Category Android: Name ="Android. Intent. Category. Default"/>

</Intent-filter>

</Activity>

Let's go to the com. Android. settings. activitypicker class to check the details.

/**

* Handle Clicking of dialog item by passing back

* {@ Link # getintentforposition (INT)} In {@ link # setresult (INT, intent )}.

*/

Public voidOnclick (dialoginterface dialog,IntWhich ){

Intent intent = getintentforposition (which );

Setresult (activity.Result_ OK, Intent );

Finish ();

}

It is clear that when we click the list item, it does not start the corresponding activity with intent, but returns it. This is the difference between it and intent. action_chooser action. Similarly, we can find the real processing process of intent. action_chooser from the source code. Similar to the above process, search for "android. Intent. Action. chooser" in the source code to quickly find the entry and track it. For intent. action_chooser, the author also finds an onclick method in resolveractivity and posts the following important code.

Public voidOnclick (dialoginterface dialog,IntWhich ){

Resolveinfo rI = madapter. resolveinfoforposition (which );

Intent intent = madapter. intentforposition (which );

 

......

 

If(Intent! =Null){

Startactivity (intent );

}

Finish ();

}

As previously inferred, it finally directly starts the activity corresponding to the list item selected by the user.

 

3. Document Description

Let's take a look at their respective descriptions in the document. I am not very good at English, so I posted them directly.

Action_chooser

Input: No data shocould be specified. Get * extra must have a extra_intent field containing the intent being executed, and can optionally have a extra_title field containing the title text to display in the chooser.

Output: Depends on the protocol of extra_intent.

 

Action_pick_activity

Input: Get * extra field extra_intent is an intent used with packagemanager. queryintentactivities to determine the set of activities from which to pick.

Output: Class Name of the activity that was selected.

 

4. Intent. action_pick_activity instance

Android source code is the best learning material. This action is used to add folders (userfolder) and liverfolder In the launcher application. This is not detailed here.

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.