2011-08-31 68 views
1

我有一個函數來顯示通知,我從各種活動中調用。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活動不應該打開。

爲什麼?有沒有辦法解決這個問題?

我不想在選擇通知時打開任何活動。

現在感謝。

回答

8

爲了改變一下通知時,沒有采取行動的路線,你可以按照如下設置空意圖:

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

感謝它的工作! – seba123neo

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

我想這是你有

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