1

I am using following code to open my application when clicking on Notification

mNotificationManager = (NotificationManager)
                  context.getSystemService(Context.NOTIFICATION_SERVICE);      

          PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
              i, PendingIntent.FLAG_UPDATE_CURRENT);      

          NotificationCompat.Builder mBuilder =
              new NotificationCompat.Builder(context)
              .setSmallIcon(R.drawable.ic_launcher)
              .setContentTitle(title)
              .setDefaults(Notification.DEFAULT_SOUND)
              .setStyle(new NotificationCompat.BigTextStyle()
                         .bigText(msg))
              .setContentText(msg);

         mBuilder.setContentIntent(contentIntent);
         mNotificationManager.cancel(Constants.PUSH_ID);
         mNotificationManager.notify(Constants.PUSH_ID, mBuilder.build());

The problem is, if the application is already running, it opens startup application after my current activity.

 Intent x = new Intent(context, MainActivity.class);
                                 i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                 i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                                 i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

How can i close the old and start the application new one.

Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

1 Answers1

-2

OK, i found a very cool and simple solution. I would just pass an extra boolean to my intent like i.putExtra("shouldRestart", true);

on my SplashActivity, i check

if(getIntent().getBooleanExtra("shouldRestart", false))
{
   // we need to clear all activities from top 
   finishAffinity();
}
Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193