1

我想让我的应用程序仅以纵向显示,所以我在标签中放入android:screenOrientation="portrait"Activity标签AndroidManifest.xml,并放入setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);了 Activity 的onCreate方法。

这可以将方向锁定为纵向,但是,当 Activity 启动时,它会显示一次,然后再次显示,所以你会看到一种闪光。我可以确认它onCreate也被调用了两次。

在我的应用程序中,此闪光灯会导致进一步强制关闭。

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

编辑

在我描述的活动之前,我有一个闪屏。它运行了两次,因此这个活动运行了两次(通过 Intent)两次。我通过检查此活动是否已使用初始屏幕类中的意图来解决此问题,并且它已经不再运行它。该修复与其说是修复,不如说是一种解决方法,但我希望它对人们有所帮助。

4

2 回答 2

1

不要放:“setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);”。让 AndroidManifest 完成他的工作。我认为你所做的是:

  1. 告诉您的应用程序仅在纵向模式下运行
  2. 告诉您的活动处于纵向模式,无论它是否已经这样(闪光灯必须来自此)。
  3. 我可能是错的。
于 2011-08-16T20:54:52.280 回答
1

我相信使用 Activity 的configChanges属性(在清单中)应该可以解决您的问题。ConfigChanges 属性文档

但是,您只是在解决另一个问题。你真正应该解决的是为什么这会激怒 FC?绝对没有理由发生这种情况,因此您也应该解决该问题。有关处理运行时更改的更多信息。

请注意:使用第一种方法来解决性能/用户体验问题是可以接受的。

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.

于 2011-08-16T20:47:23.103 回答