android - 如何在通知中重新打开 Activity 单击我的android

标签 android android-intent notifications

我正在开发一个应用程序,用户可以在登录 Activity 中登录。登录用户可以在仪表板 Activity 中查看他们的评论。如果服务器中有任何新评论,它会推送通知。一切都运行完美,除了一件事,即当用户单击通知时,如果仪表板 Activity 位于前面,则每次都会打开一个新的仪表板 Activity 。

我想要的是,如果用户单击通知,它只会在应用程序未运行时打开仪表板 Activity 。否则,如果仪表板 Activity 在前面,那么如果用户单击它,它将首先关闭仪表板 Activity ,然后重新打开 Activity 页面。 这是我为进入仪表板 Activity 而编写的代码。

    Intent startActivityIntent = new Intent(this, DashboardActivity.class); 
    startActivityIntent.putExtra("NotificationMessage", service_notification);
    startActivityIntent.putExtra("flag", 1);
    startActivityIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK );
    PendingIntent launchIntent = PendingIntent.getActivity(this, 0,
            startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    earthquakeNotificationBuilder
                .setContentIntent(launchIntent)
                .setContentTitle(no_of_review + " " + "new review is there")
                .setAutoCancel(true);   

我尝试了很多方法,但没有得到解决方案。谁能帮我?提前致谢。

最佳答案

以及 androidmanifest.xml 中的 android:launchMode="singleTask" ,以便您可以和 android:clearTaskOnLaunch="true

        <activity
            android:name=".DashboardActivity"
            android:launchMode="singleTask"
            android:clearTaskOnLaunch="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

关于android - 如何在通知中重新打开 Activity 单击我的android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16229596/

相关文章:

安卓开发 |推文一个字符串

java - 问 - 切换用户的全局设置(WiFi、位置等) - 2 个想法.. 有什么想法吗?

android - 在不使用 android :launchMode ="singleTask" 的情况下在新任务中打开 android Activity

android - 图库中的图像未显示

Swift:从 appDelegate 更改 tabBar 图标

android - 如何将PhoneGap中捕获的图像移动到SD卡中的文件夹

java - 将 JSON 数组数据分组并计算是否有两个相同的值

安卓报警管理器 : how to avoid to going off of past alarms

网页推送通知点击 Action 追踪

android - 如何添加双通知图标?