I start a service on user login which has a functionality to download many attachments in background using AsyncTask.
While the background download of attachments is in progress and user logged in to the application, I rotate my device from landscape to portrait orientation.
In portrait orientation, I have another functionality to calculate some data in background using AsyncTask. This functionality contains following code -
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Calculating...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Integer doInBackground(Integer... args) {
//Some data processing
}
@Override
protected void onPostExecute(Integer file_url) {
super.onPostExecute(file_url);
if(pDialog.isShowing()) {
pDialog.dismiss();
pDialog.cancel();
}
}
The problem is -
When I rotate the device to portrait orientation -
1) The progress dialog never gets dismissed until I restart/relaunch the application.
2) The portrait layout waits for the attachments background task to get complete and only then it calculates the async data which is in its own layout in background.
3) When the calculation of async data gets completed, the portrait layout is filled with that calculated data but the progress dialog still doesn't gets dismissed until app restart.