您在 onConfigurationChanged 中使用与 onCreate 中相同的方法吗?

发布于 2025-01-04 18:49:39 字数 695 浏览 1 评论 0原文

假设 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书信已泛黄 2025-01-11 18:49:39

如果 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文