android - 当应用程序被杀死时,c2dm 接收器不工作

标签 android android-c2dm

在应用程序标签的 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/

相关文章:

android - Android动态添加EditText、Spinner、Radiobutton

java - 如何在用户按下 imageButton 之间添加延迟?

android - 未找到客户端 token ,请设置客户端 token

android - grails C2DM - Android

android - 如何使用 Intent 限制录音时间?

java - 蓝牙通讯器

android-c2dm - Android C2DM 端口号选择

android-c2dm - 需要 C2DM collapse_key 实现解释

android - 从广播接收器启动异步任务

android - 通过设备或服务器向 Urbanairship 注册 APID