I have an activity that shows a ProgressDialog when connected to a Bluetooth device. It works fine until the screen orientation changes, but ProgressDialog. ProgressDialog disappears, and when after establishing the connection, the application calls progressDialog.dismiss (); In this case, the application crashes due to the fact that the ProgressDialog does not start. How can I prevent the ProgressDialog from declining while changing the screen orientation?
public void prepareViews(int ID, boolean state){
switch(ID){
case USERNAME_TEXTBOX:
LoginUsernameTextBox.setEnabled(state);
break;
case PASSWORD_TEXTBOX:
LoginPasswordTextBox.setEnabled(state);
break;
case LOGIN_BUTTON:
LoginButton.setEnabled(state);
break;
case LOGIN_PROGRESSBAR:
if(state == true){
LoginProgressBar.setVisibility(View.VISIBLE);
LoginProgressBar.setIndeterminate(true); }
else{
LoginProgressBar.setVisibility(View.GONE);
}
break;
case CONNECTING_DIALOG:
if(state == true){
progressDialog = ProgressDialog.show(MainActivity.this, "", "Connecting", true); }
else{
progressDialog.dismiss();
}
break;
}
}
source
share