araad1992
araad1992

Reputation: 104

activity remains open and doubles when receive notification push

I've a problem with the push notification in android.

Is this, I've an app with 2 activities,the first is a menu and another I show a map.

In the app use notification push for changes in the map. Now when the activity of map is visible in the screen and press the home button in the mobile this believe is in background.

Now the app receive a notification, open the notification and the load the activity of menu ok, update the data for the map and show the activity of the map, but return to the menu and press the back button to quit the application and close the activity but the another activity of the map that was in the background appear. this not close. What i can do???

Help me please!!!

The code onmessage when receive a notification is this:

@Override
   protected void onMessage(Context context, Intent intent){
      // Notificacion recibida: informamos al usuario
       String message = "Notificación Recibida";
       //"Id: " + intent.getExtras().getString("id") + " Status: " + intent.getExtras().getString("status");
       //Se crea un nuevo manejador de notificaciones
       NotificationManager manejadorNotificaciones = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

       //Se construye una notificacion basica
       NotificationCompat.Builder notificacionPersonalizacion = new NotificationCompat.Builder(this).
       setSmallIcon(drawable.ic_launcher).setContentTitle("Aviso SAT").setContentText(message);
       Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);              
       Intent intentoMapaPush =  new Intent(this, MenuPrincipal.class);       
       intentoMapaPush.putExtra("Push", "push");   
       PendingIntent contIntent = PendingIntent.getActivity(this, 0, intentoMapaPush, 0);
       notificacionPersonalizacion.setContentIntent(contIntent);
       notificacionPersonalizacion.setSound(alarmSound);
       notificacionPersonalizacion.setAutoCancel(true);
       Notification notificacion = notificacionPersonalizacion.build();
       notificacion.flags= Notification.FLAG_AUTO_CANCEL;       
       manejadorNotificaciones.notify(NOTIF_ALERTA_ID, notificacion);
   }

Upvotes: 1

Views: 245

Answers (1)

Barun
Barun

Reputation: 312

you are launching new Activity on notification click. You have to revoke the old paused activity from notification and your problem will solve. Use android:launchMode="singleInstance" in the activity declaration in the menifest file.

Once do this and let me know.

Upvotes: 1

Related Questions