PendingIntent不会调用已杀死进程的BroadcastReceiver(PendingIntent does not invoke BroadcastReceiver of killed process)
我目前正在开发一个使用IntentService的应用程序,它会做一些工作,然后设置一个PendingIntent来在某个指定的时间唤醒它自己。
我的问题是,如果proccess被杀死,则不会调用相应的静态BroadcastReceiver ,但如果我 - 例如 - 在我的Manifest中的intent-filter中设置“android.intent.action.AIRPLANE_MODE” ,则会调用它。
为了杀死应用程序,我在HTC Desire(2.3.7 CyanogenMod 7.2.0.1)的后退按钮上使用了longpress;)
这是我的清单:
<receiver android:name="com.jdev.myapp.service.MyReceiver" android:exported="false" > <intent-filter> <action android:name="android.intent.action.AIRPLANE_MODE" /> </intent-filter> //Just Used as an example <intent-filter> <action android:name="com.jdev.myapp.REINITIALIZATION" /> </intent-filter> <intent-filter> <action android:name="com.jdev.myapp.PROFILE_ENGAGED" /> </intent-filter> <intent-filter> <action android:name="com.jdev.myapp.PROFILE_DISENGAGED" /> </intent-filter> //Some more custom Actions here <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.PACKAGE_REPLACED" /> <data android:path="com.jdev.myapp" android:scheme="package" /> </intent-filter> </receiver>
我创建我的PendingIntents:
int Id; Intent engaged = new Intent(Constants.PROFILE_ENGAGED); //put some Extra PendingIntent pi = PendingIntent.getBroadcast(getBaseContext(), Id, engaged, PendingIntent.FLAG_UPDATE_CURRENT);
之后,我使用AlarmManager将其设置为计算时间...
只要进程存在,整个应用程序就可以正常工作。 但是如果进程被杀死 - 这实际上应该不是问题,因为BroadcastReceiver只需要再次启动服务,接收器就不会被调用,但正如上面提到的那样,系统内容如“android.intent.action.AIRPLANE_MODE” 。
根据文档,它实际上应该工作:
PendingIntent本身只是对系统维护的令牌的引用,该令牌描述了用于检索它的原始数据。 这意味着,即使其拥有的应用程序的进程被终止,PendingIntent本身也将保持可用于已经给出它的其他进程。 如果创建应用程序稍后重新检索相同类型的PendingIntent(相同的操作,相同的Intent操作,数据,类别和组件以及相同的标志),它将接收表示相同令牌的PendingIntent,如果它仍然有效,并且可以因此调用cancel()来删除它。
http://developer.android.com/reference/android/app/PendingIntent.html
有没有人能解决我的问题?
I'm currently working on an app that uses an IntentService, that does some work and then sets up a PendingIntent to wake itself at some specified time.
My Problem is that the respective static BroadcastReceiver gets not invoked if the proccess is killed, but it does get invoked if I - for example - set "android.intent.action.AIRPLANE_MODE" in the intent-filter in my Manifest.
For killing the app I use a longpress on the back-button on my HTC Desire (2.3.7 CyanogenMod 7.2.0.1) ;)
Here is my Manifest:
<receiver android:name="com.jdev.myapp.service.MyReceiver" android:exported="false" > <intent-filter> <action android:name="android.intent.action.AIRPLANE_MODE" /> </intent-filter> //Just Used as an example <intent-filter> <action android:name="com.jdev.myapp.REINITIALIZATION" /> </intent-filter> <intent-filter> <action android:name="com.jdev.myapp.PROFILE_ENGAGED" /> </intent-filter> <intent-filter> <action android:name="com.jdev.myapp.PROFILE_DISENGAGED" /> </intent-filter> //Some more custom Actions here <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.PACKAGE_REPLACED" /> <data android:path="com.jdev.myapp" android:scheme="package" /> </intent-filter> </receiver>
I create my PendingIntents like that:
int Id; Intent engaged = new Intent(Constants.PROFILE_ENGAGED); //put some Extra PendingIntent pi = PendingIntent.getBroadcast(getBaseContext(), Id, engaged, PendingIntent.FLAG_UPDATE_CURRENT);
After that I set it at the calculated time by using AlarmManager...
The whole app works nice as long as the process is alive. But if the process is killed - which actually should not be a problem, as the BroadcastReceiver just has to start the Service again, the Receiver gets not invoked, but as mentioned above by System stuff like "android.intent.action.AIRPLANE_MODE".
According to the docs it actually should work:
A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it. If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid, and can thus call cancel() to remove it.
http://developer.android.com/reference/android/app/PendingIntent.html
Does anybody have a solution for my problem?
原文:https://stackoverflow.com/questions/16731265
最满意答案
区域由
zonal
功能确定,zonal
功能可通过digits
参数(整数,要维护的位数)间接访问。 使用这种方法,您无法完全控制间隔数。 例如:horizonplot(SSTanom, digits = -1)
另一个解决方案是
dirXY
参数,它提供了更大的灵活性。 例如:horizonplot(SSTanom, dirXY = cut(y, 10))
遗憾的是,
cut
不会保留间隔的标签(因为Raster
无法存储字符),因此每个面板的名称与该区域没有直接关系。The zones are determined by the
zonal
function, that is indirectly accesible via thedigits
argument (integer, number of digits to maintain). With this approach you don't have full control of the number of intervals. For example:horizonplot(SSTanom, digits = -1)
Another solution is the
dirXY
argument ofhorizonplot
which gives more flexibility. For example:horizonplot(SSTanom, dirXY = cut(y, 10))
Unfortunately,
cut
does not preserve the label of the interval (because aRaster
cannot store characters), so the name of each panel is not directly related to the zone.
相关问答
更多-
在rasterVis中绘制具有重叠多边形的栅格时的范围问题(scoping issues while plotting a raster with an overlayed polygon in rasterVis)[2023-05-17]
latticeExtra::layer的帮助页面解释了: 层中使用的评估是非标准的,并且最初可能会令人困惑:您通常将面板函数(x,y等)内部的变量称为变量; 您通常可以引用存在于全局环境(工作空间)中的对象,但是在图层的data参数中按名称传递它们会更安全。 在函数内部使用layer ,可以将对象嵌入到列表中并将其传递给data参数: myplot <- function(in_rast, in_poly = NULL) { rastplot <- levelplot(in_rast, margin = ... -
确定区间的哪个部分与给定时区中的给定工作日重叠(Determine which part of an interval overlaps a given weekday in a given time zone)[2023-01-07]
测试中存在一些问题,但在稍微改变之后,它们会传递下面的代码。 原则上,这是一个问题: 取间隔,计算出任何时区内可能存在的日期。 我们可以将它转换为UTC的日期间隔,并在每个方向上将其扩展几天。 输出:一系列日期。 对于该日期序列中的每个日期,将其转换为目标区域中的间隔:开始是该区域中的开始日期; 结束是该区域第二天的开始。 (这将处理DST转换。)输出:一系列间隔。 对于该间隔序列中的每个间隔,确定该间隔与输入间隔之间的交集。 输出:一系列间隔,其中一些可能为空(对于“无交叉”) 结果是序列中的非空间隔。 ... -
区域由zonal功能确定, zonal功能可通过digits参数(整数,要维护的位数)间接访问。 使用这种方法,您无法完全控制间隔数。 例如: horizonplot(SSTanom, digits = -1) 另一个解决方案是dirXY参数,它提供了更大的灵活性。 例如: horizonplot(SSTanom, dirXY = cut(y, 10)) 遗憾的是, cut不会保留间隔的标签(因为Raster无法存储字符),因此每个面板的名称与该区域没有直接关系。 The zones are deter ...
-
您可以使用Datediff函数:DateDiff(DD,'firstDate','SecondDate')。 这是样本: select [ICPS].[dbo].[tickets].t_vrm,[ICPS].[dbo].[tickets] .t_zone_name, [ICPS].[dbo].[tickets] .t_street_name from [ICPS].[dbo].[tickets] inner join [ICPS].[dbo].[ticket_events] on [ICP ...
-
INTERVAL中的嵌套查询(Nested query in INTERVAL)[2022-12-07]
有一种简单的方法可以将整数转换为间隔,例如。 select now()+ (select 5) * '1 day'::interval 所以试试这个: UPDATE v_obligation SET current_alert_level=0, last_update_date=now()AT TIME ZONE 'PST', next_due_date = (now()+ (SELECT recurrence FROM v_obl ... -
这里已经详细回答了这个问题。 如何将时间转换为iPhone设备的时区? 您可能还想检查一下 使用TimeZones This has been answered in a fair bit of detail here. How to convert time to the time zone of the iPhone device? You might also want to check this out Using TimeZones
-
尝试 library(rasterVis) f <- system.file("external/test.grd", package="raster") r <- raster(f) levelplot(r, par.settings=list(panel.background=list(col="skyblue"))) Try library(rasterVis) f <- system.file("external/test.grd", package="raster") r <- raster(f ...
-
您可以通过在ProjectConfiguration`中调用的configureDoctrineConnection回调执行此操作: public function configureDoctrineConnection(Doctrine_Connection $connection) { $connection->exec('SET time_zone = "UTC"'); } 如果您使用多个连接,可能会出现此问题。 (编辑答案以删除有缺陷的附加方法。) You can do this via th ...
-
levelplot使用背景颜色显示NA值。 因此,您必须使用panel.background修改此颜色。 library(rasterVis) myTheme <- BTCTheme() myTheme$panel.background$col = 'gray' f <- system.file("external/test.grd", package="raster") r <- raster(f) levelplot(r, par.settings = myTheme) levelplot us ...
-
使用R中的rasterVis在堆栈中的每个图层上绘制特定点数据(Plot specific point data on each layer in stack with rasterVis in R)[2022-09-21]
使用panel.number函数,您可以根据您所在的面板对数据进行子集化: pts <- list(pts1, pts2) levelplot(r.stack) + layer(sp.points(pts[[panel.number()]], pch=20, cex=0.1, col="black")) With the panel.number function you can subset your data according to the pane ...