Reputation: 1407
I am developing an android application I am facing below two problems,
data lose : login screen when I change the landscape to portrait mode the entered text will be lost.
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
.
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.
Upvotes: 1
Views: 502
Reputation: 592
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.
<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.
I feel 1) and 2) are related, solve 1) using above and try to reproduce 2) again.
Upvotes: 0
Reputation: 7259
In order to prevent data loss, add configChanges
to the manifest, and to it set the values: screenOrientation
, screenSize
, layoutDirections
.
and if that too does not work,
override the onConfigurationChanged
method, and handle what you have to do with the data in that method.
Upvotes: 0
Reputation: 588
add below property in your mainifest file inside the activity.you can change as per your requirement
android:configChanges="orientation|screenSize|keyboard|screenLayout"
Upvotes: 1