0

I want to create an Android app which updates alarm (using AlarmManager) based on user location. As user moves 100 miles away, the alarm will be rescheduled. This app is like a scheduler app.

To solve the problem, I create a location listener which never be removed. My questions are:

  1. Will it eat my battery? I need the alarm is up-to-date with current user location.
  2. Do I have to set my application always in wake mode (wake lock)?
  3. If my solution is not good, what's your suggestion?

Thank you so much!

sancho21
  • 3,511
  • 1
  • 39
  • 45
  • [Google I/O 2009 - Coding for Life -- Battery Life, That Is][1] [What are the things which reduces (Android) battery time?][1] [1]: http://stackoverflow.com/questions/8445637/what-are-the-things-which-reduces-android-battery-time – Yaqub Ahmad Aug 20 '12 at 05:46
  • i think you can assign minTime & minDistance in your requestLocationUpdates. – rajpara Aug 20 '12 at 06:17

1 Answers1

0

Will it eat my battery? I need the alarm is up-to-date with current user location.

Yes, and there is no guarantee that your app will receive the location updates in a timely fashion (e.g., if the device is asleep).

Do I have to set my application always in wake mode (wake lock)?

Holding a WakeLock will help to keep your app running, but it will drain the battery very quickly -- especially if you're tracking a user over hundreds of miles.

If my solution is not good, what's your suggestion?

Please consider using AlarmManager to check the device location periodically. Handling an alarm every 15-30 minutes will use far less battery power than using a full-time location listener. You can register and unregister the location listener each time an alarm fires. As long as the app acquires a WakeLock when it handles each alarm (and releases the lock immediately afterward), the app will receive regular location updates and will not drain the battery. You might want to look at WakefulIntentService as a solution for handling the alarms and WakeLocks.

acj
  • 4,821
  • 4
  • 34
  • 49
  • So, even listening for coarse location updates will eat my batteries faster than using Alarm Manager. OK I got that. Thanks! – sancho21 Oct 08 '12 at 03:57
  • What about PASSIVE_PROVIDER? May I use full time location listener for that provider? – sancho21 Oct 08 '12 at 07:26
  • Using `PASSIVE_PROVIDER` will be less battery-intensive than its counterparts, but the accuracy of the locations won't be guaranteed. You may be using stale location data if no other apps or services are requesting location updates. Using `WakefulIntentService` to handle the WakeLocks and alarms is the most reliable (and battery-efficient) solution, IMO. – acj Oct 08 '12 at 12:36