How to avoid restarting activity when orientation changes on Android(如何在 Android 上的方向更改时避免重新启动活动)
问题描述
我正在创建一个在画布上绘制视图的 Android 应用.当设备的方向改变时,活动重新启动.我不想这样.
I am creating an Android app in which I'm drawing a view on a canvas. When the device's orientation changes, the activity restarts. I don't want it to.
如何避免在方向改变时重新启动活动?
How can I avoid restarting the activity when the orientation changes?
推荐答案
有多种方法可以做到,但是给定 这里,使用
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.
这篇关于如何在 Android 上的方向更改时避免重新启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Android 上的方向更改时避免重新启动活动
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
