首页 \ 问答 \ 独特的PendingIntent with Manifest声明(Unique PendingIntent with Manifest declaration)

独特的PendingIntent with Manifest声明(Unique PendingIntent with Manifest declaration)

我正在创建一个Android应用程序,它以编程方式创建在应用程序关闭时仍然存在的警报。 为了让警报持续存在,我不得不在我的Manifest中定义接收器,如下所示:

<receiver
android:name="com.blah.blah.AlarmReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="999" >
     <action android:name="com.blah.blah.ALARM" />
</intent-filter>
</receiver>

以下是我目前正在创建PendingIntents的方法。

Intent intent = new Intent(ACTION_ALARM);
PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager manager = (AlarmManager   (this.getSystemService(Context.ALARM_SERVICE ));

由于我使用常量ACTION_ALARM,因此所有警报都连接到相同的PendingIntent,因此调用.cancel()会删除所有警报。 但是,我想删除特定的警报实例。 我知道创建一个独特的PendingIntent的唯一方法是指定一个独特的动作,这与在上面定义我的Receiver在Manifest中存在冲突。 有没有其他方法可以为我的警报制作可区分的PendingIntents? 我也尝试添加数据,但似乎没有触发清单中的Receiver。

或者,如果我以编程方式为每个闹钟启动一个接收器,有没有办法让这些应用程序关闭时持续存在?

谢谢。


I am creating an Android application which programmatically creates alarms which persist when the application is closed. In order to have the alarms persist, I had to define the receiver in my Manifest like so:

<receiver
android:name="com.blah.blah.AlarmReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="999" >
     <action android:name="com.blah.blah.ALARM" />
</intent-filter>
</receiver>

Here is how I am currently creating the PendingIntents..

Intent intent = new Intent(ACTION_ALARM);
PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager manager = (AlarmManager   (this.getSystemService(Context.ALARM_SERVICE ));

Since I am using the constant ACTION_ALARM, all alarms are connected to the same PendingIntent, so calling .cancel() on that deletes all alarms. However, I want to delete specific alarm instances. The only way I know of to create a unique PendingIntent is to specify a unique action, which conflicts with defining my Receiver in the Manifest as I have above. Is there any other way to make distinguishable PendingIntents for my alarms? I tried adding Data as well, but it seemed the Receiver in the Manifest was not being triggered.

Alternatively, if I start a receiver for each alarm programmatically, is there a way to have those persist when the application is closed?

Thanks.


原文:https://stackoverflow.com/questions/33024931
更新时间:2023-06-08 11:06

最满意答案

我想说这取决于你是否想要文本到矢量转换步骤的再现性。 例如,如果要使用从第一个数据集创建的相同分类器(或其他),则需要重用矢量化器。 如果你在一个不同的数据集上使用一个新的,它将构建一个不同的词汇表,即拉出不同的标记,并使矢量不同。 这可能是你想要的一个非常不同的数据集(如果你要重新训练)。 可能是第二个数据集包含对预测至关重要的新单词。 如果你重复使用矢量化器,那些将被遗漏。

顺便说一句,如果要保存到磁盘,可以对矢量化器进行pickle。 有关示例,请参阅: 如何挑选自定义矢量图?


I would say it depends on whether or not you want reproducibility of the text-to-vector conversion step. For example, if you want to use the same classifier (or whatever) you made from the first data set, you need to reuse the vectorizer. If you fit a new one on a different data set, it will build a different vocabulary, ie pull out different tokens, and make the vectors differently. That might be what you want with a very different data set (if you're going to retrain). It could be that the second data set contains new words that are critical for predictions. Those would be missed if you reused the vectorizer.

By the way, the vectorizers can be pickled if you want to save to disk. For an example, see: how to pickle customized vectorizer?.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。