0

I want to resume main activity when user call app from notification but this code is recreating the main activity.How can I stop it ?

    int mId=1;
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setContentTitle("My notification")
            .setAutoCancel(true)
            .setSmallIcon(R.drawable.twitter)
            .setContentText("Hello World!")
            .setNumber(15);
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.setAction(Intent.ACTION_MAIN);
    resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(mId, mBuilder.build());

Also I placed android:launchMode="singleTop" to my main activity in my manifest file.How can I resolve this ?

Serkay Sarıman
  • 465
  • 1
  • 10
  • 17

1 Answers1

0

For my app I use this code to do this:

Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

And in the manifest I set the lunch mode of the MainActivity as singleTask android:launchMode="singleTask"

Gary
  • 16
  • 2