简体   繁体   English

Android应用程序设计用于在恢复时在横向显示的纵向模式

[英]android app designed for portrait mode displayed in landscape when resuming

I have designed an Android app to be displayed in portrait mode only (android:screenOrientation="sensorPortrait"). 我设计的Android应用程序只能以纵向模式显示(android:screenOrientation =“sensorPortrait”)。 It works fine except in one case: 除一例外,它工作正常:

  1. hold the tablet in portrait mode and start the app 将平板电脑保持在纵向模式并启动应用程序
  2. enter some data 输入一些数据
  3. switch off the tablet 关闭平板电脑
  4. rotate the tablet to landscape mode 将平板电脑旋转到横向模式
  5. switch on the tablet 打开平板电脑

==> the first "frame" of my app is displayed in landscape mode and then it is rotated to portrait mode, which means onDestroy() is called and so my entered data is lost. ==>我的应用程序的第一个“框架”以横向模式显示,然后旋转到纵向模式,这意味着调用了onDestroy(),因此输入的数据将丢失。

The tablet is a tab S2 8", with Android 7.0 平板电脑是一个标签S2 8“,与Android 7.0

Why is my app first displayed in landscape mode? 为什么我的应用首先以横向模式显示? Is there a way to avoid this behavior (I would like t avoid managing onSaveInstanceState()/onRestoreInstanceState() just because of this case)? 有没有办法避免这种行为(我想避免管理onSaveInstanceState()/ onRestoreInstanceState()只是因为这种情况)?

解决方案是实现ViewModel。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM