android – 即使应用程序关闭(滑动/滑动)也会收到GCM消息
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android – 即使应用程序关闭(滑动/滑动)也会收到GCM消息,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2077字,纯文字阅读大概需要3分钟。
内容图文
![android – 即使应用程序关闭(滑动/滑动)也会收到GCM消息](/upload/InfoBanner/zyjiaocheng/715/3e2da59e7d074e7ab78ffb9cb41e5b8b.jpg)
这是在MainActivity中用作BroadcastReceiver的代码
//Initializing our broadcast receiver
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
//When the broadcast received
//We are sending the broadcast from GCMRegistrationIntentService
@Override
public void onReceive(Context context, Intent intent) {
//If the broadcast has received with success
//that means device is registered successfully
if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_SUCCESS)){
//Getting the registration token from the intent
String token = intent.getStringExtra("token");
//Displaying the token as toast
Toast.makeText(getApplicationContext(), "Registration token:" + token, Toast.LENGTH_LONG).show();
//if the intent is not with success then displaying error messages
} else if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_ERROR)){
Toast.makeText(getApplicationContext(), "GCM registration error!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Error occurred", Toast.LENGTH_LONG).show();
}
}
};
我按照本教程关于GCM
https://www.simplifiedcoding.net/android-push-notification-using-gcm-tutorial/
解决方法:
通过滑动关闭应用程序(通常称为滑动它)不会完全杀死应用程序.在Android爱好者社区中查看此answer以获取更详细的说明.你可以看到它被提到:
..It won’t directly causes services to stop..
由于GCM通知的监听器是服务,这实际上意味着您的应用程序仍有可能继续接收它们,无论它是否被刷掉.
虽然滑动应用程序的结果也可能因所运行的设备而异,但是如上所述,可以杀死/强制停止它或其他,将停止后台进程.
但是,如果结果是,应用程序被杀死/强制停止,如上面链接的答案中所述:
For stop is a complete kill of the app — all processes are killed, all services stopped, all notifications removed, all alarms removed, etc.
这将导致应用程序根本没有收到任何类型的通知,因为它是从3.1版开始为Android设计的,如answer所述:
Apps that are in the stopped state do not receive broadcast Intents.
Stopped state is:
when the app is initially installed (before the user runs something in the app) or
after a Force Stop.
You can find more about this here: 07002
希望这有助于以某种方式清除某些事情.干杯! :d
内容总结
以上是互联网集市为您收集整理的android – 即使应用程序关闭(滑动/滑动)也会收到GCM消息全部内容,希望文章能够帮你解决android – 即使应用程序关闭(滑动/滑动)也会收到GCM消息所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。