独特的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
最满意答案
我想说这取决于你是否想要文本到矢量转换步骤的再现性。 例如,如果要使用从第一个数据集创建的相同分类器(或其他),则需要重用矢量化器。 如果你在一个不同的数据集上使用一个新的,它将构建一个不同的词汇表,即拉出不同的标记,并使矢量不同。 这可能是你想要的一个非常不同的数据集(如果你要重新训练)。 可能是第二个数据集包含对预测至关重要的新单词。 如果你重复使用矢量化器,那些将被遗漏。
顺便说一句,如果要保存到磁盘,可以对矢量化器进行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?.
相关问答
更多-
问题是CountVecorizer需要提前知道你的courpus中所有单词的所有内容,以便它可以有一种将单词映射到整数的方法。 (如果你能做一个“部分适合”会很好,如果它遇到新单词,它会将它们添加到最后,但据我所知目前不支持) 另一种方法是使用HashingVectorizer ; 这不需要适合,因为它只是通过固定的散列函数运行每个单词以获得其整数编码。 The problem is that the CountVecorizer needs to know in advance all what all ...
-
访问文档术语矩阵时不需要每次调用.fit_transform()(Access document-term matrix without calling .fit_transform() each time)[2021-02-21]
您可以简单地将拟合分配给变量dtm ,并且由于它是Scipy稀疏矩阵 ,因此可以使用toarray方法来打印它: from sklearn.feature_extraction.text import CountVectorizer corpus = ['the', 'quick','brown','fox'] vectorizer = CountVectorizer(stop_words='english') dtm = vectorizer.fit_transform(corpus) # vector ... -
看看如何在sklearn中实现transform()方法: https : //github.com/scikit-learn/scikit-learn/blob/a5ab948/sklearn/decomposition/base.py#L101 据此,手动还原按如下方式进行: import numpy as np from sklearn import decomposition np.random.seed(0) data = np.random.randn(100, 100) mdl = decom ...
-
输入数据类型为sklearn SVD fit_transform函数(Input data type for sklearn SVD fit_transform function)[2023-07-27]
您可以将此CSV转换为libsvm格式: -
我想说这取决于你是否想要文本到矢量转换步骤的再现性。 例如,如果要使用从第一个数据集创建的相同分类器(或其他),则需要重用矢量化器。 如果你在一个不同的数据集上使用一个新的,它将构建一个不同的词汇表,即拉出不同的标记,并使矢量不同。 这可能是你想要的一个非常不同的数据集(如果你要重新训练)。 可能是第二个数据集包含对预测至关重要的新单词。 如果你重复使用矢量化器,那些将被遗漏。 顺便说一句,如果要保存到磁盘,可以对矢量化器进行pickle。 有关示例,请参阅: 如何挑选自定义矢量图? 。 I would s ...
-
从PolynomialFeatures文档: 生成一个新的特征矩阵,该特征矩阵由度数小于或等于指定度数的特征的所有多项式组合组成。 例如,如果输入样本是二维的并且形式为[a,b],则2次多项式特征是[1,a,b,a ^ 2,ab,b ^ 2]。 在您的情况下,输出是列x所有组合,度数小于或等于1: [1, x] 。 在第一列中,您有x**0 ,第二列是x**1 From PolynomialFeatures documentation: Generate a new feature matrix consi ...
-
我笨 应该是: stop = re.split('\n|\t', open('stop_words.txt').read()) 没有括号。 不知道为什么它会在那之后把错误扔到线上。 I'm dumb. It should have been: stop = re.split('\n|\t', open('stop_words.txt').read()) without the brackets. Not sure why it threw the error on the line after that ...
-
是的,如果您只想编码字符串功能,可以跳过LabelEncoder的使用。 另一方面,如果您有一个整数的分类列(而不是字符串),那么pd.get_dummies将保持原样(例如,参见您的A或C列)。 在这种情况下,您应该使用OneHotEncoder 。 理想情况下, OneHotEncoder将支持整数和字符串,但目前正在进行此操作。 Yes, you can skip the use of LabelEncoder if you only want to encode string features. O ...
-
只需逐步打电话给他们。 gridSearchClassifier.fit(Xnew, yNew) transformed = gridSearchClassifier.transform(Xnew) fit_transform是这两行代码,根本没有实现为GridSearchCV的单一方法。 更新 从评论看,你似乎有点迷失了GridSearchCV实际上做的事情。 这是一种使用多个超参数拟合模型的元方法。 因此,一旦调用了fit ,就会在对象的best_estimator_字段中得到一个估算器。 在你的情况 ...
-
我通过将数据转换为数字来解决这个问题。 看起来,尽管错误消息指出'float64',但我的数据只是所有对象,而对象在fit_transform中效果不佳。 使用以下命令将我的数据更改为浮点数: df = df.apply(lambda x: pd.to_numeric(x,errors='ignore'))解决了该问题。 I solved this by casting my data to numeric. It appears that, although the error message state ...