Android 安卓未决意图?
我有一个挂起的意图,它设置报警,并从数据库获取行id和时间等参数。我想取消报警,所以我会发送另一个具有相同信息的未决意图,然后取消(我想从不同的文件中取消)。我只允许在任何时候设置一个警报,因为这是我的应用程序的工作方式,因为只有一个警报设置来自该等待的意图是否存在,我可以为该意图执行全部取消 我有一个挂起的意图,它设置报警,并从数据库获取行id和时间等参数Android 安卓未决意图?,android,Android,我有一个挂起的意图,它设置报警,并从数据库获取行id和时间等参数。我想取消报警,所以我会发送另一个具有相同信息的未决意图,然后取消(我想从不同的文件中取消)。我只允许在任何时候设置一个警报,因为这是我的应用程序的工作方式,因为只有一个警报设置来自该等待的意图是否存在,我可以为该意图执行全部取消 我有一个挂起的意图,它设置报警,并从数据库获取行id和时间等参数 pendingent上没有“参数”。我将把它解释为“额外的” 我想取消报警,所以我会发送另一个具有相同信息的未决意图,然后取消(我想从不同
pendingent
上没有“参数”。我将把它解释为“额外的”
我想取消报警,所以我会发送另一个具有相同信息的未决意图,然后取消(我想从不同的文件中取消)
它不是“发送”,而是“创建”。否则,是的,这是正确的
我可以为了这个目的取消一切吗
只有一个警报
在警报调度方面,额外费用并不重要。如果您有一个意图
(I1)包装在挂起内容
(PI1)中,并使用它来安排报警,然后如果您创建了一个具有相同组件/动作/数据/类型的意图
(I2),将其包装在挂起内容
(PI2)和取消()
报警中,它将取消PI1报警。类似地,如果使用PI2计划新警报,它将删除旧的PI1警报
我有一个挂起的意图,它设置报警,并从数据库获取行id和时间等参数
pendingent
上没有“参数”。我将把它解释为“额外的”
我想取消报警,所以我会发送另一个具有相同信息的未决意图,然后取消(我想从不同的文件中取消)
它不是“发送”,而是“创建”。否则,是的,这是正确的
我可以为了这个目的取消一切吗
只有一个警报
在警报调度方面,额外费用并不重要。如果您有一个
意图
(I1)包装在挂起内容
(PI1)中,并使用它来安排报警,然后如果您创建了一个具有相同组件/动作/数据/类型的意图
(I2),将其包装在挂起内容
(PI2)和取消()
报警中,它将取消PI1报警。类似地,如果您使用PI2计划一个新的报警,它将删除旧的PI1报警。因为我相信代码示例可以帮助您理解这一点,请参见以下内容:
/*
* An alarm can invoke a broadcast request
* starting at a specified time and at
* regular intervals.
*/
public void sendRepeatingAlarm()
{
Calendar cal = Utils.getTimeAfterInSecs(30);
String s = Utils.getDateTimeString(cal);
this.mReportTo.reportBack(tag, "Schdeduling Repeating alarm in 5 sec interval starting at: " + s);
//Get an intent to invoke TestReceiver class
Intent intent = new Intent(this, TestReceiver.class);
intent.putExtra("message", "Repeating Alarm");
PendingIntent pi = this.getDistinctPendingIntent(intent, 2);
// Schedule the alarm!
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(),
5*1000, //5 secs
pi);
}
protected PendingIntent getDistinctPendingIntent(Intent intent, int requestId)
{
PendingIntent pi =
PendingIntent.getBroadcast(
this, //context
requestId, //request id
intent, //intent to be delivered
0);
//pending intent flags
//PendingIntent.FLAG_ONE_SHOT);
return pi;
}
/*
* An alarm can be stopped by canceling the intent.
* You will need to have a copy of the intent
* to cancel it.
*
* The intent needs to have the same signature
* and request id.
*/
public void cancelRepeatingAlarm()
{
//Get an intent to invoke TestReceiver class
Intent intent = new Intent(this, TestReceiver.class);
//To cancel, extra is not necessary to be filled in
//intent.putExtra("message", "Repeating Alarm");
PendingIntent pi = this.getDistinctPendingIntent(intent, 2);
// Schedule the alarm!
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.cancel(pi);
}
由于我相信代码示例可以让您理解这一点,请参见以下内容:
/*
* An alarm can invoke a broadcast request
* starting at a specified time and at
* regular intervals.
*/
public void sendRepeatingAlarm()
{
Calendar cal = Utils.getTimeAfterInSecs(30);
String s = Utils.getDateTimeString(cal);
this.mReportTo.reportBack(tag, "Schdeduling Repeating alarm in 5 sec interval starting at: " + s);
//Get an intent to invoke TestReceiver class
Intent intent = new Intent(this, TestReceiver.class);
intent.putExtra("message", "Repeating Alarm");
PendingIntent pi = this.getDistinctPendingIntent(intent, 2);
// Schedule the alarm!
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(),
5*1000, //5 secs
pi);
}
protected PendingIntent getDistinctPendingIntent(Intent intent, int requestId)
{
PendingIntent pi =
PendingIntent.getBroadcast(
this, //context
requestId, //request id
intent, //intent to be delivered
0);
//pending intent flags
//PendingIntent.FLAG_ONE_SHOT);
return pi;
}
/*
* An alarm can be stopped by canceling the intent.
* You will need to have a copy of the intent
* to cancel it.
*
* The intent needs to have the same signature
* and request id.
*/
public void cancelRepeatingAlarm()
{
//Get an intent to invoke TestReceiver class
Intent intent = new Intent(this, TestReceiver.class);
//To cancel, extra is not necessary to be filled in
//intent.putExtra("message", "Repeating Alarm");
PendingIntent pi = this.getDistinctPendingIntent(intent, 2);
// Schedule the alarm!
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
am.cancel(pi);
}
非常感谢,你的答案澄清了很多关于如何取消的问题:)非常感谢,你的答案澄清了很多关于如何取消的问题:)如果我有10个与应用程序相关联的提醒,我如何管理唯一id。?关于管理id有什么想法吗?@Karthick有解决方案吗?如果我有10个与应用程序means关联的提醒,我如何管理唯一的id。?关于管理身份证有什么想法吗?@Karthick有解决办法吗?