当前位置:   article > 正文

android 通知点击关闭,android-通知点击-如果应用关闭了打开的活动,如果应用打开了,则显示当前活动...

android 自定义通知点击关闭通知打开app

这个问题已经在这里有了答案:????????????>????????????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的新实例.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/241024?site
推荐阅读
相关标签
  

闽ICP备14008679号