Search code examples
androidtimertimertaskbattery

Timer, TimerTask and battery consumption


Assume there is a large set of reminders, and every reminder stores time when it should go off in long format.

What is more efficient from power consumption point of view:

  1. Create TimerTask for every reminder, even there are many reminders, and put these TimerTask instances to the Timer process to control when they should go off.

  2. Have one scheduled TimerTask process that runs every minute over this list of reminders and compares current time in milliseconds with the reminder's time in long format. And when it is necessary, it shows alarm according to the reminder.

At the first glance, the second approach should consume more power and drain the battery much more faster.

Am I right, or making many (100, 200, or even more) TimerTask instances and putting them to Timer via schedule or other relevant method will drain the battery faster?


Solution

  • You can use the AlarmManager class. It much better way than others.

    Read the official document regarding AlarmManager here