当onResume被称为后台一片空白 [英] When onResume is called background goes blank

查看:146
本文介绍了当onResume被称为后台一片空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有对话框透明的活动,它就像一个暂停菜单,显示对话框,所以当我和preSS 首页按钮,一切工作正常,但是当我重新打开对话框显示,除了背景是空白。游戏是用画布 SurfaceView 所以我不能显示对话框的屏幕上,或可我,因为我是想,但我得到的错误,每次

所以,当我preSS返回键对话框显示完美的:

但是,当我点击Home键,而长按一下Home键来重新打开应用程序,我得到这样的:

onResume code:

  @覆盖
    保护无效onResume(){
        super.onResume();
        ourSurfaceView.resume();
    }

公共无效简历(){
            isRunning = TRUE;
            ourThread =新主题(本);
            ourThread.start();
        }
 

活动该节目对话框

 公共类ShowPopUp延伸活动{

    对话myDialog;
    GameSurface ourSurfaceView;
    按钮toMenu;

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.showpopupmain);

        myDialog =新的对话框(ShowPopUp.this);
        myDialog.setContentView(R.layout.showpopup);
        myDialog.setTitle(暂停);
        myDialog.setCancelable(真正的);
        Button按钮=(按钮)myDialog.findViewById(R.id.Btn1);
        toMenu =(按钮)myDialog.findViewById(R.id.Btn2);
        toMenu.setOnClickListener(新OnClickListener(){

            @覆盖
            公共无效的onClick(视图v){
                完();
                意图菜单=新的意图(
                        com.example.mygame.Menu);
                startActivityForResult(菜单,5);
            }
        });

        button.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(视图v){
                myDialog.dismiss();
                完();
            }
        });
        myDialog.show();
        myDialog.setOnCancelListener(新DialogInterface.OnCancelListener(){

            @覆盖
            公共无效OnCancel的(DialogInterface对话){
                ShowPopUp.this.finish();

            }
        });

    }
}
 

解决方案

扩大对凯西的评论: 你可以尝试关闭该活动的的onPause(内部对话),看看你的SurfaceView的简历? 如果是这样,你可以使用onResume()再次显示对话框(重启后的表面)。

您也许应该有一个额外的标志在你的面/游戏循环保持的暂停曲目/恢复游戏状态(而不仅仅是绘制状态),这样你就可以运行图中环路(所以它是可见的),而推进实际的游戏。

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:

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

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();

            }
        });

    }
}

解决方案

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.

这篇关于当onResume被称为后台一片空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆