更改屏幕方向问题:onCreate

发布于 2024-10-06 05:46:53 字数 605 浏览 0 评论 0原文

我在更改屏幕方向时遇到问题。我有一个由服务调用的具有 2 个意图的活动。

当我旋转屏幕进入横向模式时,它会调用 onCreate。问题是我有一个按钮和通过处理程序更新的 TextField),它们似乎不再做出反应。

就像这样,当我尝试在 onCreate 中添加按钮时,但一旦视图更改为横向模式,它就不会响应:

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.call);

  Button endCall = (Button) findViewById(R.id.stopCall);
  endCall.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    /// ...
   }
  });

  handleIntent(getIntent());
 }

人们如何对待这种重新定向?有没有办法让它不回忆 onCreate 请或者请处理这种情况的最常见方法是什么?

I have an issue when changing my screen orientation. I have an activity with 2 intents that gets called by a service.

When I rotate the screen, going into landscape mode, it recalls onCreate. The issue is I have a button, and TextField which gets updated through a handler), and they don't seem to react anymore.

Like this is the code when I try also to add the button in the onCreate but it doesn't respond once the view is changed to landscape mode:

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.call);

  Button endCall = (Button) findViewById(R.id.stopCall);
  endCall.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    /// ...
   }
  });

  handleIntent(getIntent());
 }

How do people treat this reorientation please? Is there a way to have it not recall onCreate please or what is the most common way to treat this case please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

晚风撩人 2024-10-13 05:46:53

请参阅此文档了解最佳实践。 configChanges 是一个短期解决方案
http://android-developers.blogspot.com/2009 /02/faster-screen-orientation-change.html

See this documentation for best practice. configChanges is a short term solution
http://android-developers.blogspot.com/2009/02/faster-screen-orientation-change.html

残花月 2024-10-13 05:46:53

在您的情况下,您要做的就是在 onDestroy 上停止处理程序,以便可以在 onCreate 中再次重新执行它。

In your case, what you have to do is to stop the handler on onDestroy, so that it can be re-executed again in onCreate.

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