android - 更新启动 Activity 的 Intent

标签 android android-intent

当从 GCM (Google Cloud Messenger) 收到新消息时,我有一个启动显示 alert dialog 的 Activity 的 Intent 。该对话框会显示未读消息的数量,但如果在显示一条消息后又收到一条新消息,并且您还没有查看上一条消息,则该对话框应更新未读计数以反射(reflect)新消息/未读消息的数量。

但是,如果带有对话框的 Activity 处于 Activity 状态,则 Intent 不会更新对话框,所以我如何更新它,因为我无法在对话框中调用 dismiss?

有新消息时的 Intent

if((incMsgs + dlMsgs) > 0 && !mMsgType.equals("Reg")){
                edit.putBoolean(Preferences.NEW_ALERT, true).commit();
                priorityMsgs = true;
                Intent i = new Intent(this,NotificationDialog.class);
                i.putExtra("incidents", incMsgs);
                i.putExtra("dlMessages", dlMsgs);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);
            }

最佳答案

您必须重写 OnNewIntent的 Activity 。并在此更新 Ui 元素。为此,您的 Activity launchMode 需要为 singleTop

关于android - 更新启动 Activity 的 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11940268/

相关文章:

java - 启动服务时不允许绑定(bind)服务Intent

android - 自定义通知布局不适用于 Android 2.3 或更低版本

java - 将 onClick 监听器添加到 gridView 项目(根据位置启动独特的 Intent )

android - 通过 bundle 传递值并在另一个 Activity 中获取它的值

android - 在 Android 上滚动比屏幕大的图像并停在其边界处

android - SearchView 无意中启动可搜索 Activity

android - 如何在 Instagram 中分享文字

android - 从 android 4.3 连接到 BLE113 时正在记录 "Client registered, waiting for callback"

android - Google Play 游戏服务 BaseGameUtils 错误

java - Android 上的简单 MVVM 架构以及 Java 上的 AndroidX