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

540 views Asked by At

I'm not using configChanges attribute to my activity in manifest as I need to show a different layout for landscape mode. And saving few primitive data values in onSaveInstanceState() method and getting back in Bundle of onCreate(). Here are my issues :

  1. On click of a button I need to post data to server(using Volley for this). 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. Please guide me.
  2. I need to show different layout for android tablets only. The screen should not get rotated in other phones. Is there a way to specify configChanges for only other phones? How do I do this?
1

There are 1 answers

0
Vedran Kopanja On

You should probably add this in your manifest file first (note the 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().