-1

In my application I start an AsyncTask to download some data, and on the UI thread I start a ProgressDialog. The problem is when I change from portrait to landscape or vice versa, on the onPostExecute of the task I cannot dismiss the ProgressDialog. The dismiss() function is called over the instance of the ProgressDialog, but it doesn't dismiss. Why is that?

Thanks

EDIT :

I think I lose the reference of the current activity in the AsyncTask thread. Is this possible? And if it is, how do I fix it?

EDIT : Can't I keep a reference of the asyncTask and put it in the bundle?

overbet13
  • 1,654
  • 1
  • 20
  • 36
  • are you calling your `AsyncTask` in `OnCreate` or in which part of your Activity. – Herry May 15 '12 at 10:34
  • Yes, but if I flip from portrait to landscape, it is not started again, because I save in the bundle of the current activity a boolean value which tells me if I started the asyncTask or not. – overbet13 May 15 '12 at 10:36

2 Answers2

1

Try to use android:configChanges attribute of your activity to make it not recreating when switching orientation.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
1

Use Handler separately in onPostExecute method to dismiss the ProgressDialog as below:

    private Handler finishedHandler = new Handler()
{
    @Override 
    public void handleMessage(Message msg) {
        Progressdialog.dismiss();
    }
};