开发者

Android restart my activity

开发者 https://www.devze.com 2023-01-27 09:15 出处:网络
How can I do that? on button click: mycontext.finish(); and 开发者_如何学JAVAthen: start again?You could try either this:

How can I do that?

on button click:

mycontext.finish();

and 开发者_如何学JAVAthen: start again?


You could try either this:

MyActivity.finish()
Intent intent = new Intent(MyActivity.this, MyActivity.class);
startActivity(intent);

Or if that doesn't work, you could do this:

private boolean isRestarting = false;
...
// When button is pressed
isRestarting = true;
myactivity.finish();
...
// in the onDestroy() method
if(isFinishing() && isRestarting){
    Intent intent = new Intent(MyActivity.this, MyActivity.class);
    startActivity(intent);
}
0

精彩评论

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