I am writing an app with two main activities:
- MainActiviy
- DialogActivity
MainActivity is a typical application window, and DialogActivity is an activity that I have styled to appear like a dialog by setting android:theme="@style/Theme.AppCompat.Light.Dialog"
From inside MainActivity I can launch the DialogActivity with the following code.
val intent = Intent(this, DialogActivity::class.java)
startActivity(intent)
The dialog window then appears over the main one like this:
In addition to that, I would also like to be able to launch the dialog by tapping on a notification. If I have a different application open and tap the notification the dialog appears on top of the other app, like I want:
However, if I currently have MainActivity open and then tap the notification the dialog appears on top of a blank background:
This happens despite the fact that the dialog appears "on top" of the main activity window in the overview screen:
So here is my question: If I have MainActivity in the foreground and then launch the DialogActivity by tapping on an appropriate notification, can I have the DialogActivity appear on top of the MainActivity window that was open?
In other words when I tap the notification I want it to look like the first picture if the MainActivity is already open in the foreground, like the second picture if another app is in the foreground, and like the third one only if there are no apps currently open.
I am using the following PendingIntent to launch the activity from the notification. Perhaps there is a is a special set of intent flags that do what I want? Or maybe I need to do something more drastic like merging the two separate activities into a single activity?
val intent = Intent(this, DialogActivity::class.java)
intent.flags = 0
val pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)
The screenshots are from an emulator running Android 9 (Api Level 28)