gpt4 book ai didi

java - Android - 为什么 Activity 在点击通知后打开?

转载 作者:行者123 更新时间:2023-11-29 10:20:24 25 4
gpt4 key购买 nike

我有一个显示通知的函数,我从各种 Activity 中调用它。

public static void CrearNotificacion(Context pContexto, String pTituloBarra, String pTitulo, String pTexto){
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) pContexto.getSystemService(ns);

Notification notification = new Notification(R.drawable.icono, pTituloBarra, System.currentTimeMillis());
notification.defaults |= Notification.DEFAULT_SOUND;

Intent notificationIntent = new Intent(pContexto, pContexto.getClass());
PendingIntent contentIntent = PendingIntent.getActivity(pContexto, 0, notificationIntent, 0);

notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.setLatestEventInfo(pContexto, pTitulo, pTexto, contentIntent);
mNotificationManager.notify(1, notification);
}

工作完美,问题是按下通知会打开创建通知的 Activity ,这是错误的,我认为当我选择通知时 notiifcacion Activity 不应该打开。

为什么?有什么办法可以解决这个问题吗?

我不想在选择通知时打开任何 Activity 。

从现在开始感谢。

最佳答案

为了在点击通知时不执行任何操作,您可以设置一个空的 Intent,如下所示:

Intent notificationIntent = new Intent() ;
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;

关于java - Android - 为什么 Activity 在点击通知后打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7262412/

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