我有一个正在进行通知的服务。在应用程序本身,我有两个活动 - HomeActivity
和SettingsActivity
。android - 通知点击 - 如果应用程序关闭打开活动,如果应用程序打开带来显示当前活动
目前我有的是 - >点击通知:
如果应用程序被关闭 - >打开
HomeActivity
。如果当前显示的活动是
HomeActivity
,请将其置于前面而不创建新的活动。
代码:
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();
清单:我接着说:机器人: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
的新实例。
我希望在应用程序在任何活动被打开,点击通知 - >显示当前活动,并且如果应用程序被关闭和被点击的通知,的HomeActivity
开放的新实例。
我想你应该阅读这个https://developer.android.com/training/notify-user/navigation.html – Raghunandan
我把它作为重复关闭。请参阅http://stackoverflow.com/questions/5502427/resume-application-and-stack-from-notification,因为它涵盖了这个问题。 –