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

时间:2011-09-15 15:08:10

标签: android android-c2dm

在应用程序标签的清单中,我有:

<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无法启动接收器?我需要清单吗?

1 个答案:

答案 0 :(得分:1)

  

为什么?

如果您使用的是Android 3.1或更高版本,那是因为您的应用程序已进入停止状态。如果用户通过“设置”应用程序强制停止,也会发生这种情况。在用户再次手动启动您的应用之前(例如,点击启动器中的图标),您的BroadcastReceivers都不会有效。

相关问题