安卓onConfigurationChanged()不会被调用的活动 [英] Android onConfigurationChanged() is not being called in Activity

查看:107
本文介绍了安卓onConfigurationChanged()不会被调用的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认识到,有关于这个主题的几个其他职位,但这些职位不是为我工作。

I realize that there are a couple other posts on this topic, however the solutions for those posts are not working for me.

基本上,我想停止我的活动重新启动后,一个设备的方向变化。要做到这一点,我在清单文件修改的活动:

Basically, I want to cease my Activity from restarting upon a device orientation change. To do this, I have modified the activity in the manifest file:

        <activity android:name=".MyActivity" android:configChanges="orientation|keyboardHidden"></activity>

和我已经覆盖 onConfigurationChanged()在我的活动:

and I have overridden onConfigurationChanged() in my Activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    System.out.println("IN onConfigurationChanged()");
}

不过,该活动仍在重新启动时的方向变化,而 onConfigurationChanged()方法不会被调用。

However, the activity is still restarting upon an orientation change, and the onConfigurationChanged() method is not being called.

有谁知道为什么这可能是发生?

Does anyone know why this may be happening?

推荐答案

这是工作的唯一的事情是使用getLastNonConfigurationInstance()。 <一href="http://developer.android.com/reference/android/app/Activity.html#getLastNonConfigurationInstance" rel="nofollow">http://developer.android.com/reference/android/app/Activity.html#getLastNonConfigurationInstance()

The only thing that worked was using getLastNonConfigurationInstance(). http://developer.android.com/reference/android/app/Activity.html#getLastNonConfigurationInstance()

这篇关于安卓onConfigurationChanged()不会被调用的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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