Call open Activity via Notification without losing the information

Asked

Viewed 244 times

0

I’m having trouble calling an Activit via Notification, every time I press the notification Activity is loaded from scratch, losing the data that was in the one that was open.

        NotificationManagerCompat nm = NotificationManagerCompat.from(context);

    Intent it = new Intent(context, MapsActivity.class);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
                    .setDefaults(Notification.DEFAULT_ALL)
                    .setAutoCancel(true)

                    .setContentIntent(PendingIntent.getActivity(context, 0, it, PendingIntent.FLAG_UPDATE_CURRENT))
                    .setSmallIcon(R.mipmap.ic_usuario)
                    .setContentTitle("Aplicativo")
                    .setContentText(msg)
                    .setAutoCancel(true).setDefaults(2).setDefaults(1)
                    .setSound(RingtoneManager.getDefaultUri(2), 3);

    nm.notify(1, mBuilder.build());

I just want the notification to call the Activity that is open, vlw!

1 answer

1


You are probably creating another Activity, test put to the Activity in your manifest:

android:launchMode="singleTask"

Another problem may be that you are wiping the data on OnStart() or OnResume().

  • Settled with the android:launchMode="singleTask" vlw!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.