0

In my android app, how to keep the current scrolling position of the activity when the device is rotated from portrait to landscape mode? Is this needed to be done dynamically? Should I force use loaders instead of AsyncTask to achieve this condition? Thanks in advance.

K.Os
  • 5,123
  • 8
  • 40
  • 95
  • You did not post any code, but if you are correctly saving and restoring the activity state of the dynamic data in your app, then the system will correctly save and restore the view's scroll position state for you. You need to provide code or better explanation of what you're doing and what "scroll position" refers to before you get a better answer though. – dominicoder Jul 16 '17 at 18:41

2 Answers2

0

Use the attribute

android:configChanges="orientation|screenSize"

inside your activity tag in the application's AndroidManifest.xml file

Praveen Thirumurugan
  • 977
  • 1
  • 12
  • 27
  • this won't be the solution you are looking for when having a different layout or different dimensions for the landscape mode. The upper solution tells the system that you handle the layout changes by yourself and you don't do anything. If that's ok for you the solution is fine: android:configChanges="orientation|screenSize|keyboardHidden" – luckyhandler Jul 16 '17 at 18:15
  • The question was for just Scroll position. This is suffice I believe. – Praveen Thirumurugan Jul 16 '17 at 18:18
  • Please do not advise people to use the `configChanges` attribute for "quick fixes" - this is more than likely the wrong solution and will likely result in crashes or incorrect behavior down the line. See this post why: https://stackoverflow.com/questions/7818717/why-not-use-always-androidconfigchanges-keyboardhiddenorientation – dominicoder Jul 16 '17 at 18:39
0
android:configChanges="orientation|screenSize|keyboardHidden"

property in AndroidManifest.xml under Application tag must be specified for the activity required.