应用程序被终止后,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 不启动我的接收器?我需要清单中的某物吗?
In manifest in application tag I have:
<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>
And my receiving has sth like that
@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);
}
}
When my app is on or in background onReceive
method is fired, but when I kill app using AdvancedTaskKiller onRecived
stops receiving. Why?
Why Android doesn't start my receiver? Do I need sth in manifest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 Android 3.1 或更高版本,这是因为您的应用程序已进入停止状态。如果用户通过“设置”应用程序强制停止您,也会发生这种情况。在用户再次手动启动您的应用程序(例如,点击启动器中的图标)之前,您的所有
BroadcastReceiver
都不会工作。If you are on Android 3.1 or newer, it is because your application has been moved into the stopped state. This also occurs if the user force-stops you via the Settings application. Until the user manually launches your app again (e.g., taps on an icon in the launcher), none of your
BroadcastReceivers
will work.