Hey guys, I have the following code..

public class MyActivity extends Activity {
    private final static int DIALOG_TASKING = 1;

    ProgressDialog mLoadingDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        new Task().execute();
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_TASKING:
                mLoadingDialog = new ProgressDialog(this);
                mLoadingDialog.setMessage("Loading stuff..");
                mLoadingDialog.setCancelable(true);
                return mLoadingDialog;
        }
        return super.onCreateDialog(id);
    }


    private class Task extends AsyncTask<Void, Void, Void> {

        protected void onPreExecute() {
                showDialog(DIALOG_TASKING);
        }

                protected Void doInBackground(Void... unused) {
                        for (int i = 0; i < 4000000; i++) { }; // just to take 
some time up
                        return null;
                }

                protected void onPostExecute(Void unused) {
                        dismissDialog(DIALOG_TASKING);
                        Toast.makeText(MyActivity.this, "Finished..",
Toast.LENGTH_LONG).show();
                }

    }
}


The code works fine, except when I try and change screen orientation,
the progress dialog doesn't disappear and the task seems to be
executed again, I realize this is because the onCreate() method is
being called again on orientation change perhaps?

What would be the best solution for this issue?

Thanks for any response.

-- 
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