Search code examples
androidandroid-serviceandroid-alarms

Android Alarm and service trigger


Couple of question on Alarm registration and starting service on trigger.

  1. If an alarm is set at couple of mins ahead of current time and then if phone is made switch off, will the alarm trigger on next phone switch on after the schedule time passed?

  2. How to cancel / update pending intent in service? How to get request code in startCommand() method of service?

  3. Will there be a multiple instances of service created if the alarm is triggered after every 10 seconds?


Solution

    1. If "switch off" means full power down and not just "once shortly press power button to turn screen off" the answer is "no"

    2. I think you can't get request code at all. As the documentation on getService states, the requestCode field is "currently not used". You should pass all your data with Intent (third arg of getService).

    3. Will not. See http://developer.android.com/reference/android/content/Context.html#startService(android.content.Intent)

    Every call to this method will result in a corresponding call to the target service's onStartCommand(Intent, int, int) method