简体   繁体   English

旋转屏幕时更改布局并在android中保持活动状态

[英]Change layout when screen is rotated and maintain activity state in android

I'm not using configChanges attribute to my activity in manifest as I need to show a different layout for landscape mode. 我没有在清单中的活动中使用configChanges属性,因为我需要显示横向模式的其他布局。 And saving few primitive data values in onSaveInstanceState() method and getting back in Bundle of onCreate(). 并在onSaveInstanceState()方法中保存一些原始数据值,并返回到onCreate()捆绑包中。 Here are my issues : 这是我的问题:

  1. On click of a button I need to post data to server(using Volley for this). 单击按钮后,我需要将数据发布到服务器(为此使用Volley)。 I'm showing a progress dialog during the server communication. 在服务器通信期间,我正在显示进度对话框。 App is force closing If I change the device orientation when progress dialog is shown. 应用程序强制关闭如果在显示进度对话框时更改设备方向。 How can I handle progress dialog state during orientation change? 方向更改期间如何处理进度对话框状态? If I use configChanges in manifest, its not force closing but a different layout is not being shown. 如果我在清单中使用configChanges,则不会强制关闭,但不会显示其他布局。 Please guide me. 请指导我。
  2. I need to show different layout for android tablets only. 我只需要显示Android平板电脑的不同布局。 The screen should not get rotated in other phones. 屏幕不应在其他手机中旋转。 Is there a way to specify configChanges for only other phones? 有没有办法只为其他电话指定configChanges? How do I do this? 我该怎么做呢?

You should probably add this in your manifest file first (note the configChanges ): 您可能应该首先将其添加到清单文件中(注意configChanges ):

<activity android:name=".MyActivity"
          android:configChanges="orientation"
          android:label="@string/app_name">

Then override these two methods and do what you want with the data inside onSaveInstanceState() , onRestoreInstanceState() . 然后重写这两个方法,并使用onSaveInstanceState()onRestoreInstanceState()

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

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