I use a Service to upload files. While a file is being uploaded, I display a ProgressDialog.
When I rotate the screen the ProgressDialog dismisses.
How can I keep the ProgressDialog around?
I'd rather not override onConfigurationChanged.
Thanks!
I use a Service to upload files. While a file is being uploaded, I display a ProgressDialog.
When I rotate the screen the ProgressDialog dismisses.
How can I keep the ProgressDialog around?
I'd rather not override onConfigurationChanged.
Thanks!
Android should handle this automatically if you show your dialog with the showDialog(int)
method.
Expanding on Dalmas' suggestion, if you happened to be like me, where you created the dialog in a separate class for managing the async task, then one line might be all you need to add:
mProgressDialog.setOwnerActivity((Activity)mContext);
This allows the Activity to manage the dialog. A longer snippet for reference...
public DownloadCatalog(Context c) {
mContext = c;
}
public void startDownload() {
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setOwnerActivity((Activity)mContext);
mProgressDialog.setMessage("Downloading \n" + remoteDirectory);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(false);
new DownloadFileAsync().execute(fileUrl);
}
class DownloadFileAsync extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog.show();
}