I am showing a ProgressDialog in the onPreExecute method of an AsyncTask object and canceling the ProgressDialog in the onPostExecute
You want to properly handle the activity lifecycle, which means saving and restoring the state of your activity, not attempting to prevent lifecycle changes. Do some reading on AsyncTask vs. the activity lifecycle.
For example: pause-and-resume-asynctasks-android and what-to-do-with-asynctask-in-onpause.