0

I am trying to make an app that is downloading some data from the web and display it on a list. I am using AsyncTask but when I rotate the phone I don't get the results.
I want to ask what is the best way to download data and handle orientation changes? I also want to display a progress dialog so the user can see the complete percentage.

Thank you

Abhinav Singh Maurya
  • 3,283
  • 8
  • 31
  • 49
Panayiotis Irakleous
  • 2,646
  • 1
  • 21
  • 34
  • It is because the activity restarts on screen rotation, might wanna look into this: http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android – Andrew V Nov 10 '15 at 06:01

1 Answers1

2

what you can do is you can set the orientation in only one form so by this your activity is not recreated or you can add this line in your manifest that will handle orientation change

<activity name= ".YourActivity" android:configChanges="orientation|screenSize"/>

or you can save the state of you application in restore it when orientation is changed

protected void onSaveInstanceState(Bundle bundle) {
  super.onSaveInstanceState(bundle);
  bundle.putInt("param", valueInt);     // you can save values that you want to 
                                        //retain when you orientation change is done 
}

and onCreate method you can get them and assign them torelevent views

public void onCreate(Bundle  bundle) {
    if (bundle != null){
    valueInt = bundle.getLong("param");
    }
}
Zubair Akber
  • 2,492
  • 10
  • 25