0

I am developing an alarm clock Android application which needs the alarm references to be stored in the phone in case they need to be modified or deleted, for instance:

  1. The user programs an alarm for 10:30 AM
  2. The system relies on AlarmManager to program it and the alarm's PendingIntent and unique ID (a random Integer) is stored (note that for an alarm in AlarmManager to be cancelled the unique ID used to set it needs to be provided).

Assuming the user does not edit nor remove the alarms, there are three use cases:

The user exits the app WITHOUT killing it from the tasks screen Trivial. All the runtime data of the app is already present and alarms can be edited or removed without a problem.

The user exits the app AND kills it from the tasks screen By using onTaskRemoved service based on this answer, the app stores the Alarm information in a JSON file in the internal storage.

The user REBOOTS the phone Now comes the problem: the phone tries to recover the JSON file with the alarm information and reschedules them at startup.

Note that NO BOOT_COMPLETED receivers were used for this, as I'm over API level 11 and in order to leverage on this receiver the user would have to start the app just after rebooting the phone and before the broadcast message fires, which is extremely unlikely.

The app would check whether the JSON file exists, but as long as the user has closed the app previously, the file would always be present, making the system go crazy.

In summary, I need a way to delete that JSON file while/after the phone reboots so that, after rebooting, the system won't read it and launch the appropriate rescheduling sequence.

xvlaze
  • 718
  • 1
  • 6
  • 26

0 Answers0