1

I have Dialog on transparent activity and it's like a pause menu, so when dialog is shown and I press Home button everything works fine but when I reopen it Dialog shows, except the background is blank. Game is made with canvas and SurfaceView so I can't display Dialog on that screen or can I, because I was trying but I get error every time

So when I press back key Dialog shows perfectly:

enter image description here

But when I click Home button and that long click on Home button to reopen app I get this:

enter image description here

onResume code:

@Override
    protected void onResume() {
        super.onResume();
        ourSurfaceView.resume();
    }

public void resume() {
            isRunning = true;
            ourThread = new Thread(this);
            ourThread.start();
        }

Activity which shows Dialog:

public class ShowPopUp extends Activity {

    Dialog myDialog;
    GameSurface ourSurfaceView;
    Button toMenu;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.showpopupmain);

        myDialog = new Dialog(ShowPopUp.this);
        myDialog.setContentView(R.layout.showpopup);
        myDialog.setTitle("Paused");
        myDialog.setCancelable(true);
        Button button = (Button) myDialog.findViewById(R.id.Btn1);
        toMenu = (Button)myDialog.findViewById(R.id.Btn2);
        toMenu.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
                Intent menu = new Intent(
                        "com.example.mygame.Menu");
                startActivityForResult(menu, 5);
            }
        });

        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                myDialog.dismiss();
                finish();
            }
        });
        myDialog.show();
        myDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                ShowPopUp.this.finish();

            }
        });

    }
}
Blake Gibbs
  • 485
  • 1
  • 9
  • 25
  • So you have a `Activity` with a `SurfaceView` over which you pop up the dialog `Activity` and when you dismiss that the background of the `SurfaceView` is blank? What does the `ourSurfaceView.resume();` look like? – CaseyB Sep 25 '12 at 20:01
  • I posted it under onResume that's the function in other class :) when I reopen Application Dialog shows, except the background is blank. – Blake Gibbs Sep 25 '12 at 20:03
  • So the background of the Dialog is blank? – CaseyB Sep 25 '12 at 20:15
  • no the transparent activity where dialog is is black color but when i press back goes to normal again – Blake Gibbs Sep 26 '12 at 12:06
  • I'm guessing that is because that activity hasn't been recreated yet. When the activity stack was set aside to go to the Home screen for example that whole stack is saved. Then when you go back to it the OS only starts the top activity, which is the one with the transparent background. – CaseyB Sep 26 '12 at 14:21
  • so how can I achieve that background doesn't go blank? – Blake Gibbs Oct 01 '12 at 14:31
  • I edited it hope you can answer it now :) – Blake Gibbs Oct 02 '12 at 14:24
  • You can use an actual dialog instead of an Activity that looks like a dialog. That way the activity on top of the stack when your app comes back will be the one with the drawing in the background. – CaseyB Oct 02 '12 at 14:41
  • How can I draw Dialog to SurfaceView if I try it I get error – Blake Gibbs Oct 02 '12 at 14:46
  • Can you please tell me how to do that? – Blake Gibbs Oct 02 '12 at 19:27
  • I tried adding dialog to my surface view, still i face this issue on resume. Anything you can help with? – Ayyappa Mar 11 '15 at 14:42

1 Answers1

0

Expanding on Casey's comments: Could you try to dismiss the dialog inside the activity's onPause() and see if your SurfaceView resumes? If it does, you can use onResume() to show the dialog again (after resuming the surface).

You should probably have an additional flag in your surface/game loop keeping track of paused/resumed game state (not just drawing state), so you can run the drawing loop (so it's visible) without advancing the actual game.

snowdragon
  • 753
  • 7
  • 18