问题描述
这是MainActivity中用作BroadcastReceiver的代码
Here is the code that is used as BroadcastReceiver inside my MainActivity
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的本教程
I followed this tutorial about GCM
https://www.simplifiedcoding.net/android- push-notification-using-gcm-tutorial/
推荐答案
通过滑动来关闭应用程序(通常称为 将其清除 )并不完全杀死应用程序.在Android发烧友社区中查看 answer 以获得更详细的描述.您可以在那里看到其中提到的内容:
Closing the app by sliding it (more commonly known as swiping it away) doesn't totally kill the app. Check out this answer in Android Enthusiasts community for a more detailed description. You can see there that it is mentioned that:
由于GCM通知的侦听器为Service
,这实际上意味着您的应用仍然有可能继续接收它们,无论它是否被 刷掉 .
Since listeners for GCM notifications are Service
s, this would actually mean that there is still a possibility that your app may still continue to receive them regardless if it is swiped away.
尽管滑动应用程序的结果也可能因运行的设备而有所不同 ,但可能会杀死/强制停止运行该应用程序,或者如上所述,将停止后台进程.
Though the result of swiping an app may also differ depending on the device it is running, one may kill/force stop it or other just as mentioned above, will stop background processes.
但是,如果结果是,则该应用程序被杀死/强制停止,如上面链接的答案中所述:
If the result is, however, the app is killed/force stopped, as mentioned in the answer from the link above:
如本:
停止状态是:
最初安装应用程序时(在用户在应用程序中运行某些程序之前)或强制停止后.您可以在此处找到有关此内容的更多信息: http://developer.android.com/about/versions/android-3.1.html#launchcontrols
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
Hope this helps clear some things somehow. Cheers! :D
这篇关于即使关闭应用程序(滑动/滑动),仍会收到GCM通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!