Android的,如何在不破坏活动时,我旋转设备? [英] Android, how to not destroy the activity when I rotate the device?

查看:117
本文介绍了Android的,如何在不破坏活动时,我旋转设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序只能在纵向模式下,我已经为每个活动的变化,我的清单文件中的方向为纵向。但是,当我旋转设备,该活动再次重现。 如何不破坏活动?

I have an app that works only in portrait mode, and I have made the changes in my manifest file for every activity the orientation to be portrait. But when I rotate the device, the activity recreates again. How to not destroy the activity?

推荐答案

对于 12 API及以下:添加

android:configChanges="orientation"

添加屏幕尺寸如果你的目标的 API 13或以上,因为只要你的方向变化,因此做您的屏幕尺寸,否则新的设备将继续摧毁你的活动。请参阅下面蛋的回答的更多信息,使用屏幕尺寸

Add "screenSize" if you are targeting API 13 or above because whenever your orientation changes so does your screen size, otherwise new devices will continue to destroy your activity. See Egg's answer below for more information on using "screenSize"

android:configChanges="orientation|screenSize"

您在AndroidManifest.xml中的活动。这样,你的活动不会自动重新启动。请参见文档了解更多的相关信息。

to your Activity in AndroidManifest.xml. This way your Activity wont be restarted automatically. See the documentation for more infos

这篇关于Android的,如何在不破坏活动时,我旋转设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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