2

I have a game menu, which is one activity, and an actual game, which is another activity.

I also have a custom Dialog class that displays a "Loading..." text and a spinning wheel. (I could add code, but it's almost identical to a normal ProgressDialog. Nothing special about it).

I wish to start displaying this dialog from the menu activity (when loading), and continue its display for after the transition to the game activity - until the game finishes loading.

Is that even remotely possible? I didn't fid a way to extend a Dialog over 2 activities. It seems to be bound to one.

SirKnigget
  • 3,614
  • 2
  • 28
  • 61

2 Answers2

1

Is that even remotely possible?

Not as far as I know. A Dialog is a UI element and as such exists withing the 'window' of the Activity which created it. Starting a new Activity obviously means it will cover the previous one and any Dialog it's currently showing.

It seems to me there are only two simple ways of doing what you want...

  1. Make sure that what is 'loading' your game is running in some separate place (Service etc) and progress is accessible from both Activities then simply destroy the first Dialog when the second Activity is started, create a new Dialog and have it pick up from where the first one left off (with progress, messages etc).

  2. If your menu and main game play can be hosted by Fragments then simply swap a menu Fragment to a game Fragment within a single Activity. That way the Dialog will continue to exist without interruption.

Squonk
  • 48,735
  • 19
  • 103
  • 135
0

I don't think dialog can be extended with two activities, It actually requires a activity context to run. so if activity will be destroyed it will automatically leaked.

Please post answer if you find the way.

user115
  • 11
  • 2