Android intent 2: instance

Source: Internet
Author: User

The following uses an example in the android SDK to describe how intent is defined and parsed. This application allows users to browse the notepaper list and View Details of each notepaper.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.google.android.notepad">   <application android:icon="@drawable/app_notes"android:label="@string/app_name">   <provider class="NotePadProvider"android:authorities="com.google.provider.NotePad" />   <activity class=".NotesList" android:label="@string/title_notes_list">     <intent-filter>       <action android:value="android.intent.action.MAIN" />       <category android:value="android.intent.category.LAUNCHER" />     </intent-filter>     <intent-filter>       <action android:value="android.intent.action.VIEW" />       <action android:value="android.intent.action.EDIT" />       <action android:value="android.intent.action.PICK" />       <category android:value="android.intent.category.DEFAULT" />       <type android:value="vnd.android.cursor.dir/vnd.google.note" />     </intent-filter>     <intent-filter>       <action android:value="android.intent.action.GET_CONTENT" />       <category android:value="android.intent.category.DEFAULT" />       <type android:value="vnd.android.cursor.item/vnd.google.note" />     </intent-filter>   </activity>    <activity class=".NoteEditor" android:label="@string/title_note">     <intent-filter android:label="@string/resolve_edit">       <action android:value="android.intent.action.VIEW" />       <action android:value="android.intent.action.EDIT" />       <category android:value="android.intent.category.DEFAULT" />       <type android:value="vnd.android.cursor.item/vnd.google.note" />     </intent-filter>     <intent-filter>       <action android:value="android.intent.action.INSERT" />       <category android:value="android.intent.category.DEFAULT" />       <type android:value="vnd.android.cursor.dir/vnd.google.note" />     </intent-filter>   </activity>   <activity class=".TitleEditor" android:label="@string/title_edit_title"android:theme="@android:style/Theme.Dialog">     <intent-filter android:label="@string/resolve_title">       <action android:value="com.google.android.notepad.action.EDIT_TITLE" />       <category android:value="android.intent.category.DEFAULT" />       <category android:value="android.intent.category.ALTERNATIVE" />       <category android:value="android.intent.category.SELECTED_ALTERNATIVE" />       <type android:value="vnd.android.cursor.item/vnd.google.note" />     </intent-filter>   </activity></application></manifest>

(1) The first activity in the example is com. google. android. notepad. noteslist, which is the main entry of the application, provides three functions, which are described by three intent-filters:
1. The first entry is to enter the top-level entrance of the notepaper application (the action is Android. App. Action. Main ). Android. App. Category. launcher indicates that the activity will be listed in launcher.
2. When type is vnd. android. cursor. DIR/vnd. google. note, you can view the available notes (the action is Android. app. action. view), or let the user select a note and return it to the caller (the action is Android. app. action. pick ).
3. The third is when the type is vnd. android. cursor. item/vnd. google. note, return a selected note to the caller (the action is Android. app. action. get_content), but the user does not need to know where to read the note.

(2) The second activity is com. Google. Android. notepad. noteeditor. It displays a note for the user and allows the user to modify it. It defines two intent-filters, so it has two functions. The first feature is when the data type is vnd. android. cursor. item/vnd. google. note, you can view and modify a note (the action is Android. app. action. view and Android. app. action. edit ). The second feature is that when the data type is vnd. android. cursor. DIR/vnd. google. note: displays a new note interface for the caller and inserts the new note into the note list (the action is Android. app. action. insert ).

(3) The last activity is com. Google. Android. notepad. titleeditor, which allows users to edit the title of the notepaper. In the unique intent-filter of this activity, a private action: COM. Google. Android. notepad. Action. edit_title indicates that you are allowed to edit the title of the notepaper. Like the previous view and edit actions, when calling this intent, you must specify a specific note (type: VND. Android. cursor. Item/vnd. Google. note ). The difference is that only the title in the note data is displayed and edited here.
In addition to the default category (Android. Intent. Category. Default), the title editor also supports two standard categories: Android. Intent. Category. Alternative and Android. Intent. Category. selected_alternative. After these two categories are implemented, other activities can call queryintentactivityoptions (componentname, intent [], intent, INT) to query the action provided by this activity, without the need to know its specific implementation; or call addintentoptions (INT,
Int, componentname, intent [], intent, Int, menu. item []) create a dynamic menu. It should be noted that the intent-filter has a clear name (specified by Android: Label = "@ string/resolve_title"). When users browse data, if this activity is an optional data operation, specifying a specific name can provide users with a better control interface.

Http://blog.csdn.net/jinlking/archive/2009/05/06/4153254.aspx ()

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.