Pending Intent does not launch Activity if app is already open or in background

Viewed 1268

In my app, i have a widget. If user clicks on widget, I am opening SplashScreen using pending intent using below code.

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.widget_main_layout, pendingIntent);

This code works fine is app is not open and launch my splash screen.

However if app is already open and in background and if i click on widget then my SplashScreen not opening and instead only app comes to the froeground.

Could anyone let me know whats wrong with my code?

2 Answers

Use this code

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

Set the flag of the intent you are passing to the pending Activity to:

Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK

Related