2

I need to open app in current state, without any new instance of my main Acitivity

Here is my code

Intent intent = new Intent(baseActivity, MainActivity.class);
    intent.putExtra("FROM_NOTIFICATION", true);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(baseActivity, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

and

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(baseActivity)
            .setSmallIcon(getNotificationIcon()).setLargeIcon(BitmapFactory.decodeResource(baseActivity.getResources(), R.drawable.ic_launcher))
            .setContentTitle(baseActivity.getResources().getString(R.string.app_name))
            .setContentText(message)
            .setOngoing(true)
            .setContentIntent(pendingIntent);
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

How can I do this? Or is there another way?

kadik
  • 149
  • 1
  • 11

1 Answers1

0

Try setting flag to the intent as below..

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

instead of

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);

in your code.

Hope this helps you. Let me know for queries.

Swaminathan V
  • 4,663
  • 2
  • 22
  • 32