我目前正在开发一个使用 IntentService 的应用,它会做一些工作,然后设置 PendingIntent 以在指定的时间唤醒自己。
我的问题是,如果proccess被终止,则不会调用相应的静态BroadcastReceiver ,但如果我 - 例如 - set “android.intent.action.AIRPLANE_MODE,它会被调用“在我的Manifest中的intent-filter中。
为了杀死应用程序,我在HTC Desire(2.3.7 CyanogenMod 7.2.0.1)的后退按钮上使用了长按;)
这是我的清单:
<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
有没有人能解决我的问题?
答案 0 :(得分:0)
正如CommonsWare指出的那样,杀死这样的过程
为了杀死应用程序,我在HTC Desire(2.3.7 CyanogenMod 7.2.0.1)的后退按钮上使用了长按
似乎非常具有破坏性,因为它也 - 在我的情况下 - 显然删除了与我的应用程序相关的警报,这不是预期的。
要模拟你的进程被杀死使用
DDMS =&gt;高亮显示你app的过程=&gt;点击STOP
答案 1 :(得分:0)
这是按预期工作的 - 您使用的特定Cyanogenmod UI相当于进入设置/应用/ [详细应用信息]并点击强制停止&#34;按钮。这会将应用程序恢复到刚刚安装的状态,并且在该状态下,如果没有直接的用户交互,则不允许应用程序运行。 &#34;停止&#34;这样的应用故意不接收广播。