views:

65

answers:

1

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?

+3  A: 

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
thank you sephy
Srinivas
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
oh then you have to check the "finished" status from the asynctask no?
Sephy
Thank u sephy i got it.
Srinivas
For future : when an answer has worked for you, please check the accepted answer below the vote tag on the left. This will increase your rate.
Sephy
Thank you very much sephy
Srinivas
where would i get android e books or materials to read ? i mean for free.
Srinivas
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