在应用程序标签的 list 中我有:
<receiver
android:name=".MyC2dmReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actual message -->
<intent-filter>
<action
android:name="com.google.android.c2dm.intent.RECEIVE" />
<category
android:name="com.my.app" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action
android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category
android:name="com.my.app" />
</intent-filter>
</receiver>
我的接收有这样的东西
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) {
handleRegistration(context, intent);
} else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
handleMessage(context, intent);
}
}
当我的应用程序打开或处于后台时 onReceive
方法被触发,但是当我使用 AdvancedTaskKiller 终止应用程序时 onRecived
停止接收。为什么?
为什么 Android 不启动我的接收器?我需要 list 中的某物吗?
最佳答案
Why?
如果您使用的是 Android 3.1 或更新版本,那是因为您的应用程序已进入停止状态。如果用户通过“设置”应用程序强制停止您,也会发生这种情况。在用户再次手动启动您的应用程序(例如,点击启动器中的图标)之前,您的所有 BroadcastReceivers
都不会工作。
关于android - 当应用程序被杀死时,c2dm 接收器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7433129/