首页 \ 问答 \ PendingIntent不会调用已杀死进程的BroadcastReceiver(PendingIntent does not invoke BroadcastReceiver of killed process)

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
更新时间:2022-12-08 11:12

最满意答案

区域由zonal功能确定, zonal功能可通过digits参数(整数,要维护的位数)间接访问。 使用这种方法,您无法完全控制间隔数。 例如:

horizonplot(SSTanom, digits = -1)

horizo​​nplot和数字

另一个解决方案是dirXY参数,它提供了更大的灵活性。 例如:

horizonplot(SSTanom, dirXY = cut(y, 10))

horizo​​nplot和cut

遗憾的是, cut不会保留间隔的标签(因为Raster无法存储字符),因此每个面板的名称与该区域没有直接关系。


The zones are determined by the zonal function, that is indirectly accesible via the digits 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)

horizonplot and digits

Another solution is the dirXY argument of horizonplot which gives more flexibility. For example:

horizonplot(SSTanom, dirXY = cut(y, 10))

horizonplot and cut

Unfortunately, cut does not preserve the label of the interval (because a Raster cannot store characters), so the name of each panel is not directly related to the zone.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。