Android - 为什么活动在点击通知后打开?

问题描述:

我有一个函数来显示通知,我从各种活动中调用。Android - 为什么活动在点击通知后打开?

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); 
} 

完美的作品,问题是,按压通知打开创建该通知的活动,这是错误的,我认为当我选择通知notiifcacion活动不应该打开。

为什么?有没有办法解决这个问题?

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

现在感谢。

为了改变一下通知时,没有采取行动的路线,你可以按照如下设置空意图:

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

感谢它的工作! – seba123neo

Intent notificationIntent = new Intent(pContexto, pContexto.getClass()); 

我想这是你有

Intent notificationIntent = new Intent(pContexto, yourClass.class);