<分区>
我有一个持续通知的服务。在应用程序本身中,我有两个 Activity - HomeActivity
和 SettingsActivity
。
目前我所拥有的是->点击通知时:
如果应用已关闭 -> 打开
HomeActivity
。如果当前显示的 Activity 是
HomeActivity
,则将其置于最前面而不创建新的 Activity。
代码:
resultIntent = new Intent(context, HomeActivity.class);
resultPendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = mBuilder
.setSmallIcon(notificationData.getImageSrc()) // the status icon
.setTicker("HealthChecker") // the status text
.setWhen(System.currentTimeMillis()) // the time stamp
.setContentTitle("HealthChecker") // the label of the entry
.setContentText(notificationData.getText()) // the contents of the entry
.setOngoing(true).setContentIntent(resultPendingIntent)
.build();
list :我添加了`android:launchMode="singleTop":
<activity
android:name=".ui.HomeActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar"></activity>
我遇到的问题是:
当我在 SettingsActivity
中并单击通知时,它会打开一个新的 HomeActivity
实例。
我想要的是当应用程序在任一 Activity 中打开并单击通知时 -> 显示当前 Activity ,如果应用程序关闭并单击通知,则打开HomeActivity
的新实例。