I am showing a notification in Android. This is working fine. Now I want to focus MyApp if the User clicks on the Notification. I know I can pass an Intent to the Notification, so I could start any Activity I want. But I do not wont to start a specific activity, I just want to go back into the app. And if the App is not running then I want to start the app normally and also not a specific Activity.
So those three scenarios:
A: MyApp is running in background, but does not have focus -> Focus MyApp
B: MyApp is not running -> Start MyApp normally
C: MyApp is running and also has focus -> Do nothing
My Code for the Notification:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channelId)
.setContentTitle(title)
.setContentIntent(intent) // -> here I could parse an Intent, I know...
// But that is not exactly what I want
I found nothing on Google for that. Is that possible?
Try this as pending intent:
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
This will :
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