简体   繁体   English

数据丢失并在横向和纵向模式下强制关闭android

[英]data lose and force close in landscape and portrait mode android

I am developing an android application I am facing below two problems, 我正在开发以下两个问题所面临的android应用程序,

  1. data lose : login screen when I change the landscape to portrait mode the entered text will be lost. 数据丢失 :当我将横向更改为纵向模式时,登录屏幕会丢失输入的文本。

  2. force close : Inside the application when I captured the image form camera then I change the portrait to landscape mode some time getting force close and image not showing in ImageView . 强制关闭 :在应用程序内部,当我捕获图像相机时,我将肖像更改为横向模式,一段时间后会强制关闭并且图像未在ImageView显示。

How to solve this problem? 如何解决这个问题呢? I should not lock the application in portrait mode and I have no idea to solve this please suggest me any useful links and sample code it might be useful for me. 我不应该将应用程序锁定为纵向模式,我不知道要解决此问题,请向我建议任何有用的链接和示例代码,这可能对我有用。

在活动内的清单文件中添加以下属性。您可以根据需要进行更改

android:configChanges="orientation|screenSize|keyboard|screenLayout"

In order to prevent data loss, add configChanges to the manifest, and to it set the values: screenOrientation , screenSize , layoutDirections . 为了防止数据丢失,添加configChanges到清单,并将其设定值: screenOrientationscreenSizelayoutDirections

and if that too does not work, 如果那也不起作用,

override the onConfigurationChanged method, and handle what you have to do with the data in that method. 覆盖onConfigurationChanged方法,并处理该方法中的数据。

1) 1)

android:configChanges="orientation|screenSize|keyboard|screenLayout"

add this to you AndroidManifest.xml file for which makes sure onCreate() is not called again when orientation change happens, but only the ui rendered will change maintaining the user entered data on UI. 将其添加到您的AndroidManifest.xml文件中,以确保在发生方向更改时不会再次调用onCreate(),但只有渲染的ui会更改,以保持用户在UI上输入的数据。

      <activity
        android:name="LoginActivity"
        android:configChanges="orientation|screenSize"
        android:label="@string/app_name"
        android:logo="@drawable/menu_button"
        android:windowSoftInputMode="adjustPan|stateHidden" >

2) need more info, however this might be case of when orientation gets changed ui views will be recreated hence will be null for some very small fraction of time and your code might be trying to access the same view in this time. 2)需要更多信息,但是这可能是方向改变时的情况。ui视图将被重新创建,因此在很小的时间内将为空,并且您的代码此时可能试图访问同一视图。

I feel 1) and 2) are related, solve 1) using above and try to reproduce 2) again. 我觉得1)和2)是相关的,请使用上述方法解决1),然后再次尝试重现2)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在横向模式下强制关闭,但在纵向中不强制关闭 - Force Close in Landscape Mode, but not in Portrait 将人像旋转到风景时,我要关闭力量,我尝试了android:configChanges =“ keyboard | keyboardHidden”并以人像模式工作吗? - Getting Force Close when rotating portrait to landscape and I tried android:configChanges=“keyboard|keyboardHidden” and working in portrait mode? Android - 在横向和纵向模式之间切换会使 Intent 失去价值 - Android - switching between landscape and portrait mode makes Intent lose values 根据屏幕大小在Android中强制纵向或横向模式 - Force portrait or landscape mode in android depending on screen size 纵向模式下的Android Landscape VideoView - Android Landscape VideoView in portrait mode 适用于Android应用程序的横向和纵向模式 - Landscape and portrait mode for android application 平板电脑Android中的横向和纵向模式 - Landscape and portrait mode in tablet Android Android 中的横向模式更改为纵向 - Landscape Mode change to portrait in Android Android-以横向方向强制肖像视图 - Android - Force portrait view in landscape orientation Android相机为横向,但以纵向模式使用 - Android camera is in landscape but used in portrait mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM