Android Activity,如何使用Java代码覆盖manifest的android:configChanges?
我正在编写一个自定义 Activity 类(将其用作其他 Activity 类的超类),它覆盖了许多默认功能。我想要的功能之一是方向处理,虽然我可以做到,但它需要
android:configChanges="orientation"
在清单中。有没有办法在 java 代码中强制执行与上面一行相同的操作?
I'm coding a custom Activity class (using it as a super class for my other Activity classes) where it's overriding many default functionalities. One of these functionalities I want is orientation handling, and while I can do it, it requires
android:configChanges="orientation"
in the manifest. Is there a way to enforce the same thing as the line above, but in java code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您仍然需要在 XML 中包含该属性,但也可以在 Java 中处理它;请参阅我的博客文章: http:// c0deattack.wordpress.com/2010/12/25/dealing-with-screen-orientation-changes-manually/
编辑:您无法设置 configChanges 属性以编程方式。我想这与创建活动的方式有关。它们首先从 XML 创建,然后调用活动实现中的重写方法。 API 中没有任何内容可以让您更改 configChanges 属性。
You'll still need to include the attribute in the XML but you can handle it in Java too; see my blog post here: http://c0deattack.wordpress.com/2010/12/25/dealing-with-screen-orientation-changes-manually/
Edit: You cannot set the configChanges attribute programmatically. I guess it's to do with the way an Activity is created. They're created from the XML first and then the overridden methods in your activity implementation are invoked. There's nothing in the API that lets you change the configChanges attribute.