2010-09-08 11 views

Respuesta

14

Llame al setLatestEventInfo() en el objeto Notification, proporcionando un PendingIntent que iniciará su actividad cuando toquen su entrada en el cajón de notificaciones. Aquí está a sample project demostrando esto.

+0

que pueda empezar la actividad cuando se hace clic en la notificación barra de notificaciones. Pero parece que Crea nueva actividad, aunque la actividad actual se está ejecutando ahora. Traté de pasar Flag a 'Intent' cuando llamé' PendingIntent', pero parece que no funcionó. Entonces, ¿qué tan cerca de la actividad actual antes de crear nueva actividad cuando se hace clic en la notificación? –

+0

@HuyTower: 'setFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)' en su 'Intención' debería funcionar. – CommonsWare

+0

@CommonsWare: ¡Funciona perfecto para mí! –

11

Suponiendo que notifNotification es su objeto:

Intent notificationIntent = new Intent(this.getApplicationContext(), ActivityToStart.class); 
PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, notificationIntent, 0); 
notif.contentIntent = contentIntent; 
+1

Puedo comenzar la actividad cuando hago clic en la notificación en la barra de notificaciones. Pero parece que Crea nueva actividad, aunque la actividad actual se está ejecutando ahora. Traté de pasar Flag a 'Intent' cuando llamé' PendingIntent', pero parece que no funcionó. Entonces, ¿qué tan cerca de la actividad actual antes de crear nueva actividad cuando se hace clic en la notificación? –

1

Aquí está el código para llamar a la actividad cuando se hace clic en la notificación

Notification notif = new Notification(R.drawable.ic_launcher,"List of Contacts...", System.currentTimeMillis()); 
Intent notificationIntent = new Intent(context,AllContacts.class); 
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,   notificationIntent, 0); 
notif.setLatestEventInfo(context, from, message, contentIntent); 
nm.notify(1, notif); 
+1

Puedo iniciar actividad cuando hago clic en la notificación en la barra de notificaciones. Pero parece que Crea nueva actividad, aunque la actividad actual se está ejecutando ahora. Traté de pasar Flag a 'Intent' cuando llamé' PendingIntent', pero parece que no funcionó. Entonces, ¿qué tan cerca de la actividad actual antes de crear nueva actividad cuando se hace clic en la notificación? –

Cuestiones relacionadas