Skip to content

Commit c98629e

Browse files
committed
Fix bug where the app crashes if the orientation changes during the download
1 parent 7f72dd1 commit c98629e

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,19 @@ And add this provider in the application tag :
5353
Add the entirety of the package `selfupdate`.
5454

5555
In the onCreate of your activity, add this to check if there is an update at the start of the application :
56+
5657
```java
5758
if (savedInstanceState == null)
5859
SelfUpdate.checkUpdate(this, "https://api.github.com/repos/burgyl/SelfUpdatingApp/releases/latest");
5960
```
6061

62+
or this if you support API before 21 :
63+
64+
```java
65+
if (savedInstanceState == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
66+
SelfUpdate.checkUpdate(this, "https://api.github.com/repos/burgyl/SelfUpdatingApp/releases/latest");
67+
```
68+
6169
You have to adapt the above URL to match your repository.
6270

6371
### Resources

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "ch.lburgy.selfupdatingapp"
99
minSdkVersion 21
1010
targetSdkVersion 29
11-
versionCode 12
12-
versionName "1.0.11"
11+
versionCode 13
12+
versionName "1.0.12"
1313

1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1515
}

app/src/main/java/ch/lburgy/selfupdatingapp/selfupdate/SelfUpdate.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ public void update(long bytesRead, long contentLength, boolean done) {
121121
activity.runOnUiThread(new Runnable() {
122122
@Override
123123
public void run() {
124-
progressBar.setProgress(progress);
124+
if (!activity.isDestroyed())
125+
progressBar.setProgress(progress);
125126
}
126127
});
127-
if (done) alertDialog.dismiss();
128+
if (done && !activity.isDestroyed()) alertDialog.dismiss();
128129
}
129130
};
130131

app/src/main/res/values/strings.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<resources>
22
<string name="app_name">Self Updating App</string>
3+
<!-- selfupdate -->
34
<string name="dialog_update_title">Do you want to update the app ?</string>
4-
<string name="dialog_downloading_title">Downloading the update</string>
5+
<string name="dialog_downloading_title">Downloading the update</string>
56
</resources>

0 commit comments

Comments
 (0)