gpt4 book ai didi

java - 打开通知时如何更新 Activity

转载 作者:行者123 更新时间:2023-11-29 23:15:56 25 4
gpt4 key购买 nike

我正在处理通知,但遇到了问题。当我点击通知时我有一个 Activity 已经打开我不想再次打开它只是更新当前 Activity 。

if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {
Intent pushNotification = null;
if (NotificationType != 0 && NotificationType != 2 && NotificationType != 5 && NotificationType != 26) {
pushNotification = new Intent(getApplication(), SplashScreen.class);
pushNotification.putExtra("NotificationType", NotificationType);
pushNotification.putExtra("ReferenceID", ReferenceID);
pushNotification.putExtra("NotificationID", ReferenceID);
pushNotification.putExtra("isread", ReferenceID);
showNotificationMessage(getApplicationContext(), title, message, time, pushNotification);
} else if (NotificationType == 0 || NotificationType == 2 || NotificationType == 5 || NotificationType == 26) {
showNotificationMessageWithNoAction(getApplicationContext(), title, message, title, null);
}
}

谁能告诉我点击通知时如何更新 Activity ?

最佳答案


你只需要声明launchModesingleTask来确保多个相同的屏幕不会打开。

Activity 有四种启动模式。他们是:
1.标准
2.单顶
3.单任务
4. 单实例

请引用此链接 Click here

<activity android:name="YOUR_SPLASH_ACTIVITY"
android:launchMode="singleTask"

>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

而在 Java 代码中,您只需覆盖 onNewIntent 方法,以刷新 activity

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);

/**
* HERE YOU JUST REFRESH , YOUR ACTIVITY
*/

}

关于java - 打开通知时如何更新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55378325/

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