Thứ Ba, 29 tháng 12, 2009

Android: Services

Because of the limited screen size of the mobile devices, typically only one application is visible and activate on device screen at any given time. Android offers Service class to create application components specifically to handle operation and functionality that should run silently, without a UserInterface. Android Services is higher priority than an inactive Activity, so they're less likely to be killed when the system requires resources. By using Service, you can ensure that applications continuous to run and response to events, even when they're inactive.

Android offers several techniques for application to communicate with users with an Activity providing a direct UserInterface, for ex: Notifications, Toast.
  • Toasts are a transient, non-modal Dialog-box mechanism used to display information to users without stealing focus from the active application.
  • Notifications represent a more robust mechanism for alerting users. Many users, when they're not actively using their mobile phones, they sit silent and unwatched in pocket or on a desk until it rings, vibrates or flashes. Should a user miss these alerts. This case, status bar icons are used to indicate that an event has occurred. All of these attention-grabbing antics are available within Android as Notifications.
  • Alarms provide a mechanism for fi ring Intents at set times, outside the control of your application lifecycle. An Alarm will fire even after its owner application has been closed, and can (if required) wake a device from sleep.
If your application regularly, or continuously, performs actions that don't depend directly from a user input, Services my be the answer. Start Service receive higher priority than inactive or invisible Activity, making them less likely to be terminated by run time's resource management. The only time Android will stop a Service prematurely is when it’s the only way for a foreground Activity to gain required resources; if that happens, your Service will be restarted automatically when resources become available.

Creating and Controlling Service
Services is extended from Service base class. Services are designed to run in the background, so they need to be started, stopped and controlled by other application component.

- Once you've contructed a new Service, you have to register it in the application manifest file within the service tag:

(... to be continuous...)

- Pro Android June 2009
- Profession Android Application Development.

Không có nhận xét nào:

Đăng nhận xét