开发者

set More Alarm in Android?

开发者 https://www.devze.com 2023-02-08 03:10 出处:网络
I use the following code to create alarm. String strDateTime=strDate+\" \"+strTime; DateFormat dfm = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");

I use the following code to create alarm.

String strDateTime=strDate+" "+strTime;             
            DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd HH:mm");              
            Date alarmTime = null;
            try {
                alarmTime = dfm.parse(strDateTime);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            long setAlarmTime=alarmTime.getTime();

            Intent myIntent = new Intent(context, MyAlarmService.class);
            pendingIntent = PendingIntent.getService(context, 0, myIntent, 0);

            Alarm开发者_开发技巧Manager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

            //set time and get the Intent 
            alarmManager.set(AlarmManager.RTC_WAKEUP, setAlarmTime, pendingIntent);

If i set more than one alarm the last one will be executed.How can i add more alarm time in android?


Try to give every of your Intent (myIntent in code) some random data (via setData call) on every AlarmManager.set call

AlaramManager resets the alarm, previously set for the same PendingIntent (and yours PendingIntents are always the same)

0

精彩评论

暂无评论...
验证码 换一张
取 消