2011-10-07 9 views
10

He visto muchos ejemplos de cómo hacer que algo suceda cuando el usuario hace clic en una notificación, pero en realidad no quiero que pase nada. Si el usuario hace clic en la notificación, quiero que la notificación simplemente desaparezca y el usuario NO se lleve a ninguna parte.¿Cómo escribir una notificación que no hace absolutamente nada cuando se hace clic?

En mi código a continuación, mientras que FLAG_AUTO_CANCEL borra la notificación de la barra de estado, cuando el usuario hace clic en mi notificación, se los lleva a "Mi Actividad".

¿Cómo puedo crear una notificación que no haga nada?

Notification notification = new Notification(R.drawable.success, res.getString(R.string.messages_sent), System.currentTimeMillis()); 

     //Define the expanded message and intent 
     Context context = getApplicationContext(); 
     CharSequence contentTitle = res.getString(R.string.messages_sent_ellipsis); 


     Intent notificationIntent = new Intent(this, MyActivity.class); 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 
     notification.setLatestEventInfo(context, contentTitle, mStrSuccessMessage, contentIntent); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     //Pass the notification to the notification manager 
     mNotificationManager.notify(1, notification); 
+1

posible duplicado de [¿Cómo puedo cancelar una notificación cuando el usuario hace clic en ella?] (Http://stackoverflow.com/questions/7682009/how-can-i-cancel-a-notification-when-the- user-clicks-on-it) –

Respuesta

17

Cambio

Intent notificationIntent = new Intent(this, MyActivity.class); 

a

Intent notificationIntent = new Intent(); 

haría el trabajo. Lo esencial es que si no quieres nada, dale un intento en blanco.

Cuestiones relacionadas