0

in my app in a particular activity i have a text view and a button. Whenever the user clicks the button an xml file gets parsed over the text view. In my xml file i have around 50 question tags and they get parsed one by one. When the user in around 30 question and he rotates the app from landscape to portrait or vice verse the question's once again gets started from the beginning. How to avoid these problem and maintain in the same question

Siva K
  • 4,968
  • 14
  • 82
  • 161

3 Answers3

1

You have to save the question's position in the onSaveInstanceState() method and restore it in the onRestoreInstanceState() method.

Michael
  • 53,859
  • 22
  • 133
  • 139
1

This sounds like you need to save the state of the application as its being rotated. If you attached an Orientation listener, then you should be able to handle this fairly easily.

http://developer.android.com/reference/android/view/OrientationEventListener.html

This should help with being able to do it programatically.

Also you want to save the state of your application in these methods:

onSaveInstanceState(Bundle state)

onRestoreInstanceState(Bundle state)

These methods are used to save information of your application as it goes through the Application Lifecycle.

Read more here: http://developer.android.com/reference/android/app/Activity.html

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
1

In android when orientation is changed your activity is re-created. You have to options to solve this.

  1. Declare your activty android:configChanges="orientation" in your Manifest. Your activity won't be destroyed and onConfigurationChanged will be called with the new configuration.
  2. You have to save the state of the activty before it's destroyed and restore it before it's created.
Mojo Risin
  • 8,136
  • 5
  • 45
  • 58