I created a progressdialog following the new "fragment way" with this code:
public class DialogUpdateTrackRecords extends DialogFragment {
public static DialogUpdateTrackRecords newInstance() {
DialogUpdateTrackRecords frag = new DialogUpdateTrackRecords();
return frag;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public ProgressDialog onCreateDialog(Bundle savedInstanceState) {
this.setCancelable(false);
ProgressDialog dialog= new ProgressDialog(getActivity());
dialog.setTitle("Caricamento tragitti");
dialog.setIndeterminate(true);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMessage("Sending something");
return dialog;
}
}
and I show it from an activity like this way:
FragmentManager fm= getSupportFragmentManager();
uploadDialogFrament= (DialogFragment) getSupportFragmentManager().findFragmentByTag("sendDialog");
if(uploadDialogFrament!=null)
uploadDialogFrament.dismiss();
FragmentTransaction ft= fm.beginTransaction();
uploadDialogFrament= DialogUpdateTrackRecords.newInstance();
uploadDialogFrament.show(ft,"sendDialog");
fm.executePendingTransactions();
((ProgressDialog)uploadDialogFrament.getDialog()).setMax(trackRecordSize);
if( trackRecordSize > 1 )
((ProgressDialog)uploadDialogFrament.getDialog()).setIndeterminate(false);
As you can see, I get a reference to the dialog and I set it (depending on my needs). Everything works like a charm but.. if I rotate the device, the dialog goes back to its pristine state instead of retaining (in the example: the bar is set back to an indefinite state) my new settings. I checked if I was creating and displaying a new dialog erroneously, but this is not the case. So.. how could I keep my changes over the recreation of the activity?