开发者

Call OnCreate by pressing the backbutton

Hy!

M开发者_如何学编程y code:

if(keyCode == KeyEvent.KEYCODE_BACK)
    {
        if (menuestate == 1)
            Main.this.onCreate(null);
        }
        }

if i press the backbutton i see the oncreate for a half second an then the homescreen occur

Whats wrong?


This is not how it is supposed to work. If you want to restart your activity you need to call finish() and then restart it through the Intent, like this:

if(keyCode == KeyEvent.KEYCODE_BACK)
{
    if (menuestate == 1)
        finish();
        Intent intent = new Intent(Main.this, Main.class);
        startActivity(intent);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜