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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With