赞
踩
这个问题已经在这里有了答案:????????????>????????????Resume application and stack from notification????????????????????????????????????7个
我有正在通知的服务.在应用程序本身中,我有两个活动-HomeActivity和SettingsActivity.
目前我拥有的是->单击通知时:
>如果应用已关闭->打开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();
清单:我添加了`android:launchMode =“ singleTop”:
android:name=".ui.HomeActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar">
我有的问题是:
当我进入SettingsActivity并单击通知时,它将打开HomeActivity的新实例.
我想要的是在任一活动中打开应用程序并单击通知时->显示当前活动,如果应用程序已关闭且单击了通知,请打开HomeActivity的新实例.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。