您在 onConfigurationChanged 中使用与 onCreate 中相同的方法吗?
假设 onCreate
看起来像这样
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initializeElements();
setOnClickListeners();
updateTable();
}
onConfigurationChanged
:
- 必须看起来相同(见下文),
- 我不必使用任何
onCreate
方法还是 - 我遗漏了一些东西?
这是另一种方法。
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main);
initializeElements();
setOnClickListeners();
updateTable();
}
Let's say that onCreate
looks like this
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initializeElements();
setOnClickListeners();
updateTable();
}
Does onConfigurationChanged
:
- has to look the same (see below),
- I do not have to use any of
onCreate
methods or - I have omitted something?
Here's the other method.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main);
initializeElements();
setOnClickListeners();
updateTable();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 onConfigurationChanged 与 onCreate 相同,则不需要 onConfigurationChanged,因为 android 会调用 onCreate。
当您不希望 android 重新启动您的应用程序时,通常会使用 OnconfigurationChanged,因此您通常只需重新创建视图并继续运行您的程序。
If the onConfigurationChanged is the same as onCreate, you shouldn't need to have an onConfigurationChanged because android will call onCreate.
OnconfigurationChanged is normally used when you don't want android to restart your app, so you usually just recreate the view and continue running your program.