And the answer is … you cannot. When Android wants to free up memory to cater other applications and/or services, the schedules in an AlarmManager also gets removed.

So your app or widget scheduled to run at some point may not run at all because the schedule is gone. From my experiencewhen I was still in the development process of my widget, the only possible way I made the same schedule running  again in the AlarmManager was to take advantage of the updatePeriodMillis attribute in the XML file of the app widget provider file.

Since the minimum that the app widget provider updates the widget is 30 minutes, this was where I placed my code to add the same schedule to the AlarmManager.

Do not worry if you keep adding it because if there is an existing PendingIntent object in the AlarmManager, it will cancel it and replace it with the new one.

Reading through all forum posts that I came across, I may have to agree that there is no way to make it persistent as there may be a chance that users will uninstall your app if they find something in their phone that keeps on running even when they manually exited it (e.g. Service).

Related Posts Plugin for WordPress, Blogger...