更改屏幕方向问题:onCreate
我在更改屏幕方向时遇到问题。我有一个由服务调用的具有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅此文档了解最佳实践。 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
在您的情况下,您要做的就是在
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 inonCreate
.