I am using AsyncTask to download files. There i implemented progress:
//Updating progress dialog
protected void onProgressUpdate(Integer... changed) {
progressDialog.setProgress(changed[0]);
}
//STARTED
@Override
protected void onPreExecute() {
try {
progressDialog = new ProgressDialog(context);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage(context
.getString(R.string.message_loading));
progressDialog.setCancelable(false);
progressDialog.show();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
Everything is working fine in portrait and landscape. For notification that file was downloaded i am using interface.
So wrong is when i start downloading my file in portrait or landscape and while it not done i rotate device then progress disappear and callback fire exception as there is no where to go.
When i rotate device my Activity is re created, so how to do this properly. I need to restrict that when downloading is started user couldn’t rotate device, then how to do that.
Or there are solutions to this ?
If you want to restrict orientation while downloading then just before starting downloads use this code. this will restrict users device orientation.
This code you can use after finishing orientation which allow user to rotate device again.
hope it will help you.