我是在一个Activity中添加闹铃,在另一个Activity中取消。
添加闹铃代码如下:
c.setTimeInMillis(System.currentTimeMillis());
//设置日历的小时和分钟
c.set(Calendar.HOUR_OF_DAY, cursor.getInt(cursor.getColumnIndex("hour1")));
c.set(Calendar.MINUTE, cursor.getInt(cursor.getColumnIndex("minute1")));
//将秒和毫秒设置为0
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Intent intent = new Intent(addAlarmToDatabase.this,AlarmReceiver.class); //创建Intent对象
intent.setAction(String.valueOf(System.currentTimeMillis()));
intent.putExtra("id",id);
intent.putExtra("name", name);
intent.putExtra("hour",hour1);
intent.putExtra("minute",minute1);
intent.putExtra("size",alarmeditusage.getText().toString());
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pi = PendingIntent.getBroadcast(addAlarmToDatabase.this,id, intent, 0); //创建PendingIntent
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),61*1000,pi); //设置闹钟
删除闹铃代码如下:
Intent intent = new Intent(deleteAlarmFromDatabase.this,AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(deleteAlarmFromDatabase.this, id, intent, 0);
//获取闹钟管理器
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
很急!谢谢大家了!
------解决方案--------------------
保存数据的方法有很多种。
恭喜LZ
------解决方案--------------------
怎么解决的?
楼主分享一下经验啊
------解决方案--------------------
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Test.this,AlamrReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(Test.this, 0, intent, 0);
AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
am.cancel(pi);
}
------解决方案--------------------
调AM的cancel
------解决方案--------------------
把解决方法搞出来啊。
------解决方案--------------------
就是啊 楼主要分享啊
------解决方案--------------------
是不是回复就有积分??
------解决方案--------------------
应该是,呵呵。
------解决方案--------------------
是这样吗?楼主,跟大家交流下。。