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

查看:26
本文介绍了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?

推荐答案

对于 API 12 及以下:添加

android:configChanges="orientation"

如果您的目标是 API 13 或更高版本,请添加screenSize",因为每当您的方向发生变化时,您的屏幕尺寸也会发生变化,否则新设备将继续破坏您的活动.有关使用screenSize"的更多信息,请参阅下面的 Egg 回答

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 中的活动.这样您的 Activity 就不会自动重新启动.请参阅文档了解更多信息

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

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

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