0

How can I run services in the background of a battery manager Android application?

How would I display or receive a notification when the battery is low or when certain criteria are met?

For example, for an alarm, when the current time equals the alarm time the alarm rings.

4

1 回答 1

0

You have 3 options:

  1. You create a long running Service. It spawns off a thread that checks the things you mentioned periodically. I wouldn't advise this tho, these services tend to be killed on the long run by the os. Also, you'd have to use Wake Locks to prevent the system to put the cpu on idle when the phone goes idle after some minutes of inactivity - also stopping you service.

  2. Check out the available system events for which you can register Broadcast Receivers. If you find suitable ones (I think there's one for indicating low battery levels), write receivers for them.

  3. Use the timing service to register intents to be fired off on regular intervals. These intents would start a service (a short running one) that would do your thing.

于 2011-02-09T11:57:15.760 回答