hpi*_*que 203 android android-activity
Activity在Android中重新加载是一个好习惯吗?
最好的方法是什么?this.finish然后this.startActivity与活动Intent?
Sus*_*ush 485
你可以简单地使用
finish();
startActivity(getIntent());
Run Code Online (Sandbox Code Playgroud)
Activity从内部刷新一个.
AMA*_*NGH 46
对于那些不想在重新创建()方法之后看到闪烁的人,只需使用
finish();
overridePendingTransition(0, 0);
startActivity(getIntent());
overridePendingTransition(0, 0);
Run Code Online (Sandbox Code Playgroud)
小智 37
这是我在更改从首选项更改返回后重新加载活动的操作.
@Override
protected void onResume() {
super.onResume();
this.onCreate(null);
}
Run Code Online (Sandbox Code Playgroud)
这实际上导致活动重绘自己.
更新: 更好的方法是调用recreate()方法.这将导致重新创建活动.
nin*_*edt 10
我需要快速更新我的一个应用程序中的消息列表,所以在关闭我所在的对话框之前,我只是刷新了我的主UI活动.我相信还有更好的方法可以实现这一点.
// Refresh main activity upon close of dialog box
Intent refresh = new Intent(this, clsMainUIActivity.class);
startActivity(refresh);
this.finish(); //
Run Code Online (Sandbox Code Playgroud)
Riz*_*wan 10
我看到了之前使用Intent重新加载活动的答案.这些可以工作但你也可以使用Activity类本身给出的recreate()方法.
而不是写这个
//关闭对话框后刷新主要活动
Intent refresh = new Intent(this, clsMainUIActivity.class);
startActivity(refresh);
this.finish();
Run Code Online (Sandbox Code Playgroud)
这可以通过仅写这个来完成
recreate();
Run Code Online (Sandbox Code Playgroud)
Android包括一个进程管理系统,用于处理活动的创建和销毁,这在很大程度上抵消了您从手动重新启动活动中看到的任何好处.您可以在Application Fundamentals中查看有关它的更多信息
但是,良好的做法是确保onPause和onStop方法释放您不需要保留的任何资源,并使用onLowMemory将您的活动需求减少到绝对最小值.
重新加载整个活动可能是一项繁重的任务。只需将需要刷新的代码部分放入(kotlin)即可:
override fun onResume() {
super.onResume()
//here...
}
Run Code Online (Sandbox Code Playgroud)
爪哇:
@Override
public void onResume(){
super.onResume();
//here...
}
Run Code Online (Sandbox Code Playgroud)
并在需要时调用“ onResume() ”。
从一个意图开始,activity然后关闭activity.
Intent refresh = new Intent(this, Main.class);
startActivity(refresh);//Start the same Activity
finish(); //finish Activity.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
375098 次 |
| 最近记录: |