Pergunta

I want to launch an Activity(Afresh, Without any previously retained state) on a notification click. IF this Activity is already in the stack, bring this to top but without any previous state.

So Far i have tried setting Flags to Passed Intent.

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

But They Don't serve the purpose. Any suggestions how i could achieve this.

Foi útil?

Solução

If you remove |Intent.FLAG_ACTIVITY_SINGLE_TOP from your launch this should restart the activity.

Specifying |Intent.FLAG_ACTIVITY_SINGLE_TOP in the launch flags causes the existing instance to be reused. If you remove it the existing instance will be finished and a new instance will be launched.

Outras dicas

Here You Go.

  NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);

Intent notificationIntent = new Intent(context, HomeActivity.class);

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

PendingIntent intent = PendingIntent.getActivity(context, 0,
        notificationIntent, 0);

notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);

to open application in anystate.

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");

startActivity(LaunchIntent);

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top