views:

23

answers:

1

Hi,

I want to add an alarm, so I used the following code:

    public void SetAlarm(Alarm alarm)
{
    mTimeTarget = PendingIntent.getBroadcast(mContext, alarm.getRowID(), 
            new Intent(HomeScreen.ACTION_CHECK_TIME_ALARMS), PendingIntent.FLAG_UPDATE_CURRENT);
    mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarm.getAlarmTime().toMillis(true), mTimeTarget);
}

But this doesn't seem to work. (I tried on the emulator, and when the time comes, nothing happens - my onReceive function on my class that extends BroadcastReceiver isn't called).

Here is how I initialized mAlarmManager on the constructor (it is private because this class is singleton):

    private AlarmsManager(Context con)
{
    mContext = con;

    mAlarmManager = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE);
}

Any idea what I did wrong? Thanks!

A: 

Perhaps alarm.getAlarmTime().toMillis(true) is not in the timebase of SystemClock.elapsedRealtime(). If getAlarmTime() returns a android.text.format.Time object, this is most certainly incorrect.

CommonsWare
I have managed to fix this! The problem was in the time, as you said. Thank you very much!!!
Roee