Android电子锁方向和Double创建 [英] Android Lock Orientation and Double Create

查看:139
本文介绍了Android电子锁方向和Double创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的应用程序只有在纵向显示的,所以我已经把的android:screenOrientation =肖像活动的Andr​​oidManifest.xml ,并已经把 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 在活动的的onCreate 方法。

I want to make my application displayed only in portrait orientation, so I have put android:screenOrientation="portrait" in the Activity tag in AndroidManifest.xml, and have put setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); in the Activity's onCreate method.

这工作的方向锁定为纵向,不过,活动开始时,它显示了自己一次,然后再次表明自己,让你看到一个排序闪光灯。我可以证实,的onCreate 被调用两次为好。

This works to lock the orientation to portrait, however, when the Activity starts, it shows itself once, then shows itself again, so you see a sort of flash. I can confirm that onCreate is being called twice as well.

本闪光灯在我​​的应用程序造成进一步的强制关闭后。

This flash is causing further force closes later in my application.

我怎样才能消除这个闪光?

How can I eliminate this flash?

我有一个启动画面我已经描述的活动之前显示。它被运行两次,所以跑这两次活动(通过一个Intent)的两倍。我通过,如果这活动已经使用闪屏类的意图盯着检查修复了这个问题,并且它有,不要再运行它。此修复程序更是一个解决办法比的修复程序,但我希望它能帮助的人。

I had a splash screen displaying before the activity I had described. It was being run twice, and therefore ran this activity twice (via an Intent) twice. I fixed this issue by checking if this activity had already been stared using an intent in the splash screen class, and it had, not to run it again. The fix was more of a workaround than a fix, but I hope it helps people.

推荐答案

我相信,使用活动的 configChanges 属性(在清单)应该解决您的问题。 ConfigChanges属性文档

I believe that using the Activity's configChanges attribute (in the manifest) should solve your problem. ConfigChanges attribute documentation

然而的,你只是绕来绕去的另一个问题。你真正应该解决的是的为什么的是挑衅FC?绝对没有任何理由要做到这一点,所以你也应该解决这个问题。在处理运行更多信息更改

However, you are just going around another problem. What you really should address is why is that provoking FC? There is absolutely no reason for that to happen so you also should solve that problem. More info in handling runtime changes.

请注意:使用第一种方式是可以接受的解决性能/ UX问题虽然

Please note: using the first approach is acceptable to address the performance/UX issues though.

万一你想知道为什么的onCreate 被调用两次,一旦我得到了这个问题,我认为这是与具有方向固定,然后有其他活动被创建,但在一个不同的方位。第二活动开始之前,前活动改变为后者的方向。请记住,键盘锁也是一个活动!我不知道,如果发生这种情况因为这个原因,虽然

Just in case you wonder why onCreate is called twice, once I got into this problem and I think that it was related to having the orientation fixed and then having another activity being created but in a different orientation. Before the second activity was started, the former activity changed into the orientation of the latter. And remember that keyguard is also an Activity! I'm not sure if this happens for this reason though.

这篇关于Android电子锁方向和Double创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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