Fix race condition with progress dialog
This commit is contained in:
@@ -31,6 +31,7 @@ public class ProgressDialogManager {
|
|||||||
public static final String TAG_PROGRESS_DIALOG = "progressDialog";
|
public static final String TAG_PROGRESS_DIALOG = "progressDialog";
|
||||||
|
|
||||||
private FragmentActivity activity;
|
private FragmentActivity activity;
|
||||||
|
private boolean isDismissed = false;
|
||||||
|
|
||||||
public ProgressDialogManager(FragmentActivity activity) {
|
public ProgressDialogManager(FragmentActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
@@ -42,7 +43,9 @@ public class ProgressDialogManager {
|
|||||||
|
|
||||||
public void showProgressDialog(
|
public void showProgressDialog(
|
||||||
String progressDialogMessage, int progressDialogStyle, CancellationSignal cancellationSignal) {
|
String progressDialogMessage, int progressDialogStyle, CancellationSignal cancellationSignal) {
|
||||||
|
if (isDismissed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final ProgressDialogFragment frag = ProgressDialogFragment.newInstance(
|
final ProgressDialogFragment frag = ProgressDialogFragment.newInstance(
|
||||||
progressDialogMessage, progressDialogStyle, cancellationSignal != null);
|
progressDialogMessage, progressDialogStyle, cancellationSignal != null);
|
||||||
|
|
||||||
@@ -52,7 +55,12 @@ public class ProgressDialogManager {
|
|||||||
// http://stackoverflow.com/questions/10114324/show-dialogfragment-from-onactivityresult
|
// http://stackoverflow.com/questions/10114324/show-dialogfragment-from-onactivityresult
|
||||||
final FragmentManager manager = activity.getSupportFragmentManager();
|
final FragmentManager manager = activity.getSupportFragmentManager();
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
handler.post(() -> frag.show(manager, TAG_PROGRESS_DIALOG));
|
handler.post(() -> {
|
||||||
|
if (isDismissed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
frag.show(manager, TAG_PROGRESS_DIALOG);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +77,8 @@ public class ProgressDialogManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void dismissAllowingStateLoss() {
|
public void dismissAllowingStateLoss() {
|
||||||
|
isDismissed = true;
|
||||||
|
|
||||||
ProgressDialogFragment progressDialogFragment =
|
ProgressDialogFragment progressDialogFragment =
|
||||||
(ProgressDialogFragment) activity.getSupportFragmentManager()
|
(ProgressDialogFragment) activity.getSupportFragmentManager()
|
||||||
.findFragmentByTag(TAG_PROGRESS_DIALOG);
|
.findFragmentByTag(TAG_PROGRESS_DIALOG);
|
||||||
|
|||||||
Reference in New Issue
Block a user