如何避免重新启动活动时,在Android的方向变化 [英] How to avoid restarting activity when orientation changes on Android

查看:113
本文介绍了如何避免重新启动活动时,在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 应对这些变化。

as you need, allows you to instead 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的方向变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆