3

I am writing an activity, that loads data from a server and displays it as a list using ArrayAdapter. For that I'm showing a progress dialog i.e loading, while it loads all data from the server. Then i dismiss the dialog in a handler. My problem is that when ever i change the orientation, the progress dialog is again shown, which is not needed, because all the data is displayed already?

Janusz
  • 187,060
  • 113
  • 301
  • 369
Srinivas
  • 1,688
  • 8
  • 30
  • 51

1 Answers1

5

I would say you have two options :
Either you force your activity not to be able to change orientation :

<activity android:name="MainActivity" android:configChanges="keyboardHidden|orientation"> 

in your manifest (documentation), which will tell the system that you want to handle orientation changes by yourself, and in this case, you won't do anything. But, you'd rather add some code in onPause() and onSaveInstanceState() because this activity might be interrupted by Android when you receive a phone call for instance. So you need to handle some saving.

Or, you choose to prevent the display of the dialog when has already been displayed, or when your background thread is running. This is easy is you use an AsyncTask for your download part, because you can use AsyncTask.getStatus which will return you the status of the task. If it is already in finished status, you have to cancel the dialog.

Sephy
  • 50,022
  • 30
  • 123
  • 131
  • My problem is that ? how to avoid display of progress dialog , which i displayed in OnCreate(). affter dissmissing dialog . i changed orientation , again activity recreated , so dialog display again ? how to avoid it ? – Srinivas Aug 09 '10 at 10:27
  • oh then you have to check the "finished" status from the asynctask no? – Sephy Aug 09 '10 at 10:40
  • where would i get android e books or materials to read ? i mean for free. – Srinivas Aug 10 '10 at 04:46
  • They aren't a lot of free material but you can find some on this page : http://speckyboy.com/2010/08/04/a-useful-selection-of-android-developer-tools-and-resources/ – Sephy Aug 10 '10 at 07:03