I have an application which uses AsyncTask to get the json file from server and so shows the Progress Bar. But while showing the progress bar and the orientation is changed, the application crashes showing VIEW NOT ATTACHED error or HAS LEAKED WINDOW error.
How to get rid of these errors? Otherwise the application works fine on AsyncTask.
My best guess from the limited information available as of now:
When you rotate your screen it goes through the normal activity lifecycle process of onPause(), onStop(), and onDestroy() as appropriate, so you have to dismiss the progressDialog in one of those methods
How i did it:
Try using this
Try this for your activity. Although it is not very clean. It can help
Try this small hack I put together... run it and observe the logcat information as you try various combinations of screen changes and pressing the hardware back key. Then try the tweak mentioned in the comments below and tinker some more. This lets you avoid android:configChanges="orientation|screenSize" which isn't preferable.
This should build as is with a minimal manifest and layout.xml file. Leave comments if I mucked it up somehow.
Well what about "locking" the screen-orientation while your AsyncTask is running?!
For example:
right before you get the JSON file from the server and
after your AsynTask is executed.