在Android中重载Activity是一个很好的做法吗?
最好的方法是什么?这一点。完成,然后这个。用Intent启动activity ?
在Android中重载Activity是一个很好的做法吗?
最好的方法是什么?这一点。完成,然后这个。用Intent启动activity ?
当前回答
以一个相同的活动开始,并关闭该活动。
Intent refresh = new Intent(this, Main.class);
startActivity(refresh);//Start the same Activity
finish(); //finish Activity.
其他回答
你可以简单地使用
finish();
startActivity(getIntent());
从Activity内部刷新Activity。
对于那些不想看到重现()方法后闪烁的人,只需使用
finish();
overridePendingTransition(0, 0);
startActivity(getIntent());
overridePendingTransition(0, 0);
这就是我所做的重新加载活动后,从一个首选项更改返回。
@Override
protected void onResume() {
super.onResume();
this.onCreate(null);
}
这本质上导致活动重绘自身。
更新:更好的方法是调用rebuild()方法。这将导致重新创建活动。
简单地使用
this.recreate();
这将触发活动中的onCreate方法
我需要在我的一个应用程序中更新消息列表,所以我只是在关闭我所在的对话框之前刷新了我的主UI活动。我相信还有更好的方法来实现这一点。
// Refresh main activity upon close of dialog box
Intent refresh = new Intent(this, clsMainUIActivity.class);
startActivity(refresh);
this.finish(); //