且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Android 上的方向更改时避免重新启动活动

更新时间:2022-01-18 22:27:33

有多种方法可以做到,但是给定 这里,使用

There are various ways to do it, but as given here, using

android:configChanges="keyboardHidden|orientation|screenSize"

允许您监听配置更改.然后,您通过覆盖 onConfigurationChanged 并调用 setContentView 来响应这些更改.

allows you to listen for the config changes. You then respond to these changes by overriding onConfigurationChanged and calling setContentView.

这就是我一直这样做的方式,但我很想知道其他人的想法.

This is the way I've been doing it, but I'd be interested to know other people's thoughts.