gpt4 book ai didi

android - 即使应用程序关闭(滑动/滑动)也会收到 GCM 通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:01:59 28 4
gpt4 key购买 nike

这是在我的 MainActivity 中用作 BroadcastReceiver 的代码

    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/

最佳答案

通过滑动关闭应用(通常称为滑动)并不会完全终止应用。看看这个 answer在 Android Enthusiasts community 中有更详细的描述。你可以看到那里提到:

..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.

这将导致该应用根本不会收到任何类型的通知,因为它是为 Android 3.1 版设计的,如本 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) orafter a Force Stop.You can find more about this here: http://developer.android.com/about/versions/android-3.1.html#launchcontrols

希望这有助于以某种方式清除一些东西。干杯! :D

关于android - 即使应用程序关闭(滑动/滑动)也会收到 GCM 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37357745/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com