Search code examples
androidandroid-servicealarmmanagerandroid-alarmsandroid-2.3-gingerbread

Is it possibile to run 2 different alarm with 2 different repeat values in a same application.in android?



Im developing a mobile application using Android 2.3
Here i want to capture the gps location and send the location co-ordinates (If it captured otherwise send 0) to web app with the one hour time gap.
The gps capturing is time and battery consuming.
In my application i use alarm manager that repeat with 1 hour time duration.If alarm arise then a receiver (BroadcastReceiver) is invoked then the gps capturing and send to server module is executed
Here when receiver notifies then gps capturing started the listener ,then immediately the location co-ordinates send to server.But here problem is location capturing time consuming so for sending module the location details remain as 0.(location not captured.But after sending to server after some time location captured)
So my plan is to create 2 alarm .One for capturing gps (Started before 10 minutes of sending server) and other alarm for sending server which is repeated for 1 hour.
Here my doubt is AlarmManager is a android system service.
Is there is possible to run 2 different alarm with 2 different repeat values (repeat with 1 hour for 1 alarm,repeat with 30 minutes for other alarm,etc) in a same application


Solution

  • Yes it is. I once created an Android app that has one alarm that fires off every 10 minutes, the other two alarms every 15.

    You simply have to create a different PendingIntent object for each alarm and add each one to the AlarmManager via the setRepeating method.