2

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:

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
sirlion
  • 287
  • 2
  • 4
  • 11
  • How much information are you talking about for B? If B can be passive, why don't you use a Toast? – cornbread ninja Nov 03 '11 at 18:20
  • I thought about that, but TOASTs disappear after X time. Besides, I want to see how my info changes in real time and I don't think you can do that with Toasts. – sirlion Nov 03 '11 at 18:23

2 Answers2

0

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

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Thanks! I'm going to try it. Quick question: Do you know if the onPause() method of the main activity invoked when using this approach? This is crucial also... Thanks! – sirlion Nov 03 '11 at 18:58
  • I'm pretty sure the onPause() method would be invoked here. It would be easy to test though. Good luck! – groomsy Nov 04 '11 at 11:12
0

Why not use a FrameLayout that is apart of your Activity? Just ensure that this View has a higher z index (make sure you declare it last in your XML layout or create it at runtime). That way you never leave your Activity.

groomsy
  • 4,945
  • 6
  • 29
  • 33