Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification bring app to front without change activity

I want to create notification that when it clicked will bring my app to front but without changing (reload or navigate out) the last activity that was shown.

I tried:

setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT))

But in the new Android 4.3 the application brought to front, but its also start a new instance of MainActivity, and I don't want this.

I want that my app will continue from the last activity that was shown.
How to do that?

like image 917
nrofis Avatar asked Oct 13 '13 19:10

nrofis


People also ask

What is notification foreground?

Foreground services show a status bar notification, so that users are actively aware that your app is performing a task in the foreground and is consuming system resources. Devices that run Android 12 (API level 31) or higher provide a streamlined experience for short-running foreground services.

What is restrict to launch in Android?

Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background. These restrictions help minimize interruptions for the user and keep the user more in control of what's shown on their screen.

How do I force an app to alert me?

Go to Settings > Notifications & status bar > Notification Manager > select the app and turn on "Allow Notifications", "Display on Lockscreen", "Display at the top of the screen", "Notification Sound and Vibration", and "Priority notification". Then, restart your phone.


1 Answers

You don't ever set Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT. That flag is set by Android when it brings the activity to the front. You setting it has no effect.

There's a few ways to do what you want. Check out this answer

like image 165
David Wasser Avatar answered Sep 26 '22 19:09

David Wasser