登录后发送挂起通知 [英] Send pending notification after login

查看:72
本文介绍了登录后发送挂起通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 androidhive 。我能够成功运行项目。我在我的项目中添加了这个。所有的事情都很完美。现在我想实现,当用户从我的应用程序注销时,他不应该从服务器收到任何消息。当他再次登录后,他应该看到所有待处理的通知。我正在修复,不知道该怎么办。
这里是我的注销代码:

I am using Push notificaiton from androidhive. I am able to run the project succesfully. I have added that in my project. All the things are working perfectly. Now i want to implement that when an user logout from my app he should not receive any message from the server. and after when he logged in again he should see all the pending notifications. I am in a fix , don't know what to do. Here is my logout code:

public static void logout(Context context){             

//      GCMRegistrar.unregister(context);           

        AppConstant.setBooleanSharedPreference(context, AppConstant.SP_IS_LOGGED_IN, false);
        Intent intent = new Intent(context,LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    }


推荐答案

在这种情况下,不会从GCM注销。您可以在这里阅读 http://developer.android.com/google /gcm/adv.html#unreg-why

According to developer docs you shouldn't unregister from GCM in such situation. You can read about it here http://developer.android.com/google/gcm/adv.html#unreg-why

如果用户登录并决定了什么,而不是取消注册,则可以在onMessage()方法中检查GCMIntentService处理通知。
因此,在您的情况下,您可以在用户注销时将通知保存到数据库,并在他登录时显示。

Instead of unregistering you can check in GCMIntentService in onMessage() method if user is logged in and decide what to do with a notification. So in your case you can save notifications into DB when user is logged out and show them when he logs in.

这篇关于登录后发送挂起通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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