Android Activity, how to override manifest's android:configChanges with Java code?

ⅰ亾dé卋堺 提交于 2019-11-26 21:54:27

问题


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?


回答1:


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.




回答2:


You can add all possible value in "android:configChanges",and override method onConfigurationChanged in Activity,but only call Activity.receate() for the case you need.



来源:https://stackoverflow.com/questions/7245758/android-activity-how-to-override-manifests-androidconfigchanges-with-java-cod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!