Search code examples
javaandroidandroid-activitydialogsubactivity

how to show a "window/subactivity/dialog" on top of an Activity but keeping the focus in the Activity


My activity A is a game and it does some background operations. When I press a button in the contextual menu, I want to pop up a "small window/dialog/subactivity" (lets call it B) that appears on top of activity A and displays some data about those background operations. But I need to keep the focus on the activity A in order to continue interacting with it (playing the game).

In essence, I want to be able to see the data display by B while playing the game.

I'm not really sure how to implement this. After reading the documentation I have the next conclusions:

  • I know that I can't use Dialogs because the have the focus. Is it possible to avoid this?
  • Using a subactivity with a Dialog theme it's another option that looks tempting...but I believe that the subactivity has the focus. Ditto.
  • My last option is to try to add a LinearLayout with my data to the main Layout, "sharing/splitting" the screen. It's not pretty, but at least I know that this is possible. What I don't like about this approach is that I use the width and height of the screen.

Any suggestions? Solutions?

PS: I found some this thread here that are very related to my question:


Solution

  • Create an Activity with style Theme.Dialog. This is a normal activity which looks like a dialog, while being modeless and accepting events.

    Additional catch is in setting WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL and resetting WindowManager.LayoutParams.FLAG_DIM_BEHIND.

    See this answer for complete example: timed modeless dialog