ren*_*der 5 android google-cloud-messaging firebase-cloud-messaging
这是在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();
}
}
};
Run Code Online (Sandbox Code Playgroud)
我按照本教程关于GCM
https://www.simplifiedcoding.net/android-push-notification-using-gcm-tutorial/
AL.*_*AL. 11
通过滑动关闭应用程序(通常称为滑动它)不会完全杀死应用程序.请在Android爱好者社区中查看此答案,以获取更详细的说明.你可以看到它被提到:
..它不会直接导致服务停止..
由于GCM通知的监听器是Services,这实际上意味着您的应用程序仍然可能仍然继续接收它们,无论它是否被刷掉.
虽然滑动应用程序的结果也可能因所运行的设备而异,但是如上所述,可以杀死/强制停止它或其他,将停止后台进程.
但是,如果结果是,应用程序被杀死/强制停止,如上面链接的答案中所述:
停止是完全杀死应用程序 - 所有进程都被终止,所有服务都停止,所有通知都被删除,所有警报被删除等.
这会导致应用程序根本没有收到任何类型的通知,因为它是从3.1版开始为Android设计的,如此答案中所述:
处于停止状态的应用程序不接收广播Intents.
停止状态是:
最初安装应用程序时(在用户在应用程序中运行某些内容之前)或强制停止之后.你可以在这里找到更多相关信息:http://developer.android.com/about/versions/android-3.1.html#launchcontrols
希望这有助于以某种方式清除某些事情.干杯! :d
| 归档时间: |
|
| 查看次数: |
8068 次 |
| 最近记录: |