Lesson Plan: Unit - 06
Subject: P15A2AAD - Android Application Development
Topic of Study: Working with Live Folders
Grade/Level: Master of Computer Applications
Objective: How to use Live Folders
Time Allotment: 55 Minutes
Subject: P15A2AAD - Android Application Development
Topic of Study: Working with Live Folders
Grade/Level: Master of Computer Applications
Objective: How to use Live Folders
Time Allotment: 55 Minutes
- Working with Live Folder
INTRODUCTION
- Live folders have been introduced in Android 1.5 and let you display any source of data on the Home screen without forcing the user to launch an application. A live folder is simply a real-time view of a ContentProvider.
- A LiveFolder (android.provider.LiveFolders) is a powerful feature that complements the content provider interface. A LiveFolder is a special folder containing content generated by a content provider.
- For example, a user might want to create a LiveFolder with favorite contacts, most frequently viewed emails in a custom email application, or high-priority tasks in a task management application.
- As such, a live folder can be used to display all your contacts, your bookmarks, your email, your playlists, an RSS feed, etc. The possibilities are endless! Android 1.5 ships with a few stock live folders to display your contacts.
How it works
- When the user chooses to create a LiveFolder, the Android system provides a list of all activities that respond to the ACTION_CREATE_LIVE_FOLDER Intent. If the user chooses your Activity, that Activity creates the LiveFolder and passes it back to the system using the setResult() method.
- A LiveFolder is a special folder whose content is provided by a ContentProvider. To create a live folder, two components are required:
- An activity that can respond to the intent action ACTION_CREATE_LIVE_FOLDER. The activity is responsible for creating the live folder.
- A ContentProvider to provide the live folder items.
Lifecycle
- When a user wants to create a live folder, the system looks for all activities with the intent filter action ACTION_CREATE_LIVE_FOLDER and presents the list to the user. When the user chooses one of the activities, the activity is invoked with the ACTION_CREATE_LIVE_FOLDER action. The activity then creates the live folder and passes it back to the system by setting it as an activity result. The live folder is described by a content provider URI, a name, an icon and a display mode. Finally, when the user opens the live folder, the system queries the content provider to retrieve the folder's content.
- The LiveFolder consists of the following components:
- Folder name
- Folder icon
- Display mode (grid or list)
- Content provider URI for the folder contents
- The first task when enabling a content provider to serve up data to a LiveFolder is to provide an <intent-filter> for an Activity that handles enabling the LiveFolder. This is done within the AndroidManifest.xml file as follows:
<activity
android:name=".activity.BookShelfLiveFolder"
android:label="LiveFolder">
<intent-filter>
<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This class was deprecated in API level 14.
- Live folders are no longer supported by Android. These have been replaced by the new AppWidget Collection APIs introduced in Build.VERSION_CODES.HONEYCOMB. These provide all of the features of live folders plus many more. The use of live folders is greatly discouraged because of security issues they introduce -- publishing a live folder requires making all data shown for the live folder available to all applications with no permissions protecting it.
Assignment:
What is the Live folder? What are the components of it and why is its class removed? Explain.
- Working with Service
- Services in Android is a component that runs in the background without any user interaction or interface.
- Unlike Activities services does not have any graphical interface.
- Services run invisibly performing long running tasks - doing Internet look ups, playing music, triggering notifications etc.
- Services run with a higher priority than activities.
- Started
- A Service is started when a application component such as an activity invokes it by calling startService().
- Once started, a service can run in the background indefinitely, even if the component that started it is destroyed
- Bound
- A service is "bound" when an application component binds to it by calling bindService().
- A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with inter-process communication.
- Note: Add the service to AndroidManifest.xml
- Last but not the least, don't miss to add your service to android manifest file. If you don't add this service to manifest, you will not get any errors as well output.