Android activity folder

Source: Internet
Author: User

The active folder is introduced by SDK1.5 and allows developers to publish ContentProvider, such as contacts and media data, on the desktop of a device. The active folder in Android serves the ContentProvider as the RSS reader for publishing websites.
The working principle of the active folder is as follows:
(1) Create an icon on the home page to represent a group of rows from ContentProvider. Link by specifying a URI for the icon.
(2) When you click this icon, the system accepts the URI and uses it to drop ContentProvider. ContentProvider returns a group of rows through a cursor.
(3) As long as the cursor contains the columns (such as names, descriptions, and programs called upon clicking) desired in the active folder, the rows are displayed in ListView or GridView format.
(4) Because ListView or GridView can update their own data when the basic storage data is changed, these views are regarded as active and named after the active folder.
After learning about the concept of active folders, we will introduce how to build active folders. To build an active folder, you need two things: one activity and one specialized ContentProvider. Android uses the next activity tag to fill in the list of available activity folders. In the following example, we will use the Android built-in ContentProvider: Contacts Contact to implement an active folder for Contacts.
First, let's look at the description file: AndroidManifest. xml.
[Java]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. test. livefolder"
Android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">
 
 
<Application android: icon = "@ drawable/icon" android: label = "@ string/app_name">
<Activity android: name = ". MainActivity"
Android: label = "@ string/app_name">
<Intent-filter>
<Strong> <category android: name = "android. intent. category. DEFAULT"/>
<Action android: name = "android. intent. action. CREATE_LIVE_FOLDER"/> </strong>
</Intent-filter>
</Activity>
 
</Application>
</Manifest>

Next is the main activity class:
[Java]
Public class MainActivity extends Activity {
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );

Final Intent intent = getIntent ();
Final String action = intent. getAction ();
// Obtain data from contacts
Final Uri uri = Uri. parse ("content: // contacts/live_folders/people ");
If (LiveFolders. ACTION_CREATE_LIVE_FOLDER.equals (action )){
SetResult (RESULT_ OK, createLiveFolder (uri, "Contacts LF", R. drawable. icon ));
}
Else {
SetResult (RESULT_CANCELED );
}
This. finish ();
}
// Create an active folder
Private Intent createLiveFolder (Uri uri, String name, int icon ){
Final Intent intent = new Intent ();

// Set Intent
Intent. setData (uri );
// Activity folder name
Intent. putExtra (LiveFolders. EXTRA_LIVE_FOLDER_NAME, name );
// Activity folder icon
Intent. putExtra (LiveFolders. EXTRA_LIVE_FOLDER_ICON, Intent. Reset cuticonresource. fromContext (this, icon ));
// Display mode: List
Intent. putExtra (LiveFolders. EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders. DISPLAY_MODE_LIST );

Return intent;
}
}


Run the program, press the desktop, and select a folder. The result is as follows:

Then, select "Contact live folder" to display an active folder on the desktop,

Click this active folder. The list of active folders is empty because no contacts are recorded at this time,

After manually adding two Contact records, click the Contact LF activity folder.

The data in the active folder is indeed updated in real time.




From fwwdn's column

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.