Step #1: Make it a static inner class

Step #2: Manually associate your activity with the task in its constructor

Step #3: Return the task object from
onRetainNonConfigurationInstance() of your activity

Step #4: In onCreate() of your activity, check
getLastNonConfigurationInstance(), and if it is not null, associate
your new activity instance with the task via a setter

Step #5: Use the activity within onPostExecute()

Here is a sample project demonstrating the above:

http://github.com/commonsguy/cw-android/tree/master/Rotation/RotationAsync/

On Thu, Sep 16, 2010 at 6:22 PM, dashman <[email protected]> wrote:
> i've got an async task
>
>         private class DownloadScheduleTask extends
> AsyncTask<String,Void,String>
>         {
>                 ProgressDialog progress;
>
>                 protected void  onPreExecute()
>                 {
>
>                         progress = ProgressDialog.show( StartupActivity.this, 
> null,
> "Wait...", true, false );
>                 }
>
>                 protected String doInBackground(String... urls)
>                 {
> /* background task work here... */
>                 return data;
>                }
>
>             protected void onPostExecute( String result )
>             {
>                 progress.dismiss();
>             }
>         }
>
> when a screen is rotated, emulator crashes in onPostExecute because
> looks like
> ProgressDialog is no longer valid.
>
> how can i detect that progress instance var is no longer valid so that
> i don't call dismiss()
>
> the dialog is off the screen anyway.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to