Android GCM(推送通知):如果应用程序停止,设备不会收到通知 [英] Android GCM (push notification): device doesn't receive notification if application is stopped

查看:24
本文介绍了Android GCM(推送通知):如果应用程序停止,设备不会收到通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Android 项目中使用推送通知 (GCM).

I use push notification (GCM) in my Android project.

根据 GCM 教程,我实现了广播接收器并在 AndroidManifest.xml 中注册了它.

According to GCM tutorial I implemented broadcast receiver and registered it in AndroidManifest.xml.

即使我的应用程序关闭,这种广播接收器也应该接收消息(不仅当我的应用程序在后台而且即使它被强制停止).

This kind of broadcast receivers should receive messages even if my app is closed (not only if my app is in background but even if it was force stopped).

但它不像我预期的那样工作.如果应用程序关闭,则不会调用 onReceive() 方法.看来我对广播接收器的理解是正确的,问题出在我对 GCM 的期望中.

But it doesn't work as I expect. onReceive() method isn't being called if the app is closed. It seems that my understanding of broadcast receivers is correct and the problem is in my expectations about GCM.

可能的原因之一是,如果应用程序关闭,谷歌服务器甚至不会向设备发送通知.那么,只有在我的应用程序正在运行或在后台(但未关闭)时才能接收消息(并且 onReceive() 方法将在广播接收器中调用)是否正确?

One of the possible reasons is that google server doesn't even send a notification to the device if the app is closed. So, is it correct that my app can receive a message (and onReceive() method will be invoked in broadcast receiver) only if it's running or in background (but not closed)?

提前致谢.

推荐答案

即使我的应用程序关闭,这种广播接收器也应该接收消息(不仅当我的应用程序在后台而且即使它被强制停止).

This kind of broadcast receivers should receive messages even if my app is closed (not only if my app is in background but even if it was force stopped).

如果用户从设置"强制停止您的应用,您的代码将永远不会再次运行,直到有人手动运行您的组件之一,通常是用户手动启动活动(从 Android 3.1 开始)).因此,如果用户从设置"强制停止您的应用,您将不会在较新的设备/模拟器上收到 GCM 消息.

If a user force-stops your app from Settings, your code will never ever run again, until something manually runs one of your components, typically the user manually launching an activity (as of Android 3.1). Hence, if the user force-stops your app from Settings, you will not receive GCM messages on newer devices/emulators.

那么,我的应用程序只有在运行或在后台(但未关闭)时才能接收消息(并且 onReceive() 方法将在广播接收器中调用)是否正确?

So, is it correct that my app can receive a message (and onReceive() method will be invoked in broadcast receiver) only if it's running or in background (but not closed)?

从应用程序的角度来看,Android 中没有封闭"的概念.如果关闭"的意思是没有正在运行的进程,最后一个进程正常终止",那么是的,您应该收到 GCM 消息和其他广播.但是,同样,强制停止不会正常终止".

There is no concept of "closed" in Android from an application standpoint. If, by "closed", you mean "has no running process, where the last process was terminated normally", then yes, you should receive GCM messages and other broadcasts. But, again, force-stop is not "terminated normally".

这篇关于Android GCM(推送通知):如果应用程序停止,设备不会收到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆