当方向的变化的onStop方法被调用 [英] Onstop method is called when Orientation changes

查看:194
本文介绍了当方向的变化的onStop方法被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更改了Android应用的方向,它调用的onStop方法,然后的onCreate。如何避免caling的onStop和的onCreate时方向的变化?

When I change the orientation of the Android application, it calls onStop method and then onCreate. How to avoid caling onStop and onCreate when orientation changes?

推荐答案

这已经很长一段时间,因为这个问题一直在积极,但我窗台需要回答这个问题。我有同样的问题,找到答案。

It have been long time since this question have been active, but I sill need to answer this. I had same issue and found answer.

在清单中应添加的android:configChanges =方向|屏幕布置|的layoutDirection 在您的活动不应该呼吁方向更改默认操作

In manifest you should add android:configChanges=orientation|screenLayout|layoutDirection in your activity which should not call default actions on orientation change.

...
<activity android:name=".Activity"
  android:screenOrientation="portrait"
  android:configChanges="orientation|screenLayout|layoutDirection|screenSize" 
...

结果
而在你的活动:


And in your activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
    // This overrides default action
}

搜索结果
原来的例子:结果
http://android-er.blogspot.fi/2011/05/$p$pvent-activity-restart-when-screen.html

这篇关于当方向的变化的onStop方法被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆