Search code examples
androidandroid-activityfirebase-cloud-messaging

Android: Open activity in front of any running app


I am trying to open an activity from the FirebaseMessaging service when some message is received in onMessageReceived method. I want to show that activity in front of any running app like Facebook or Maps. But when the message was received and I started the activity it goes behind the running app.

This is the code I am using to start the activity.

val intent = Intent(this, SomeActivity::class.java)
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
                    startActivity(intent)

Any help would be appreciated.


Solution

  • starting Android 10 we have some restrictions for starting Activity entirelly from the background. check out DOC for more info and list of exceptions