Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

```
dependencies {
implementation 'com.github.ZuoHailong:AppUpdate:0.2.6'
implementation 'com.github.DrumbeatSoft:AppUpdate:0.2.7'
}

```
Expand Down
4 changes: 2 additions & 2 deletions appupdate/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 26
versionName "0.2.6"
versionCode 28
versionName "0.2.8"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private AppUpdateManager(Builder builder) {
.setCancelText(builder.cancleText)
// .setApkContentLength(builder.apkContentLength)
// .isBreakpoint(builder.breakpoint)
.show(builder.context.getFragmentManager(), "update");
.showAllowingStateLoss(builder.context.getFragmentManager(), "update");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.Manifest;
import android.app.AlertDialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -41,6 +43,7 @@
import com.yanzhenjie.kalle.Kalle;
import com.yanzhenjie.kalle.download.Callback;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -376,4 +379,29 @@ public boolean handleMessage(Message msg) {
}
});

public void showAllowingStateLoss(FragmentManager manager, String tag) {
try {
Field dismissed = DialogFragment.class.getDeclaredField("mDismissed");
dismissed.setAccessible(true);
dismissed.set(this, false);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
try {
Field shown = DialogFragment.class.getDeclaredField("mShownByMe");
shown.setAccessible(true);
shown.set(this, true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
FragmentTransaction ft = manager.beginTransaction();
if (!this.isAdded()) {
ft.add(this, tag);
}
ft.commitAllowingStateLoss();
}
}