Skip to content

Commit b5ff833

Browse files
author
isayan
committed
Fixed a bug that crashes when the screen is rotated.
1 parent c890284 commit b5ff833

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ Most of the code was created based on the following applications for creating ap
111111

112112
## Development environment
113113

114-
* JRE(JDK) 1.8以上(Open JDK)
114+
* JRE(JDK) 1.8 or later(Open JDK)
115115
* AndroidStudio 3.6.1 (https://developer.android.com/studio/index.html)

android_app/app/src/main/java/tun/proxy/SettingsActivity.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.List;
3030
import java.util.Map;
3131
import java.util.Set;
32+
import java.util.concurrent.ExecutorService;
33+
import java.util.concurrent.Executors;
3234

3335
public class SettingsActivity extends AppCompatActivity {
3436
private static final String TAG = "SettingsActivity";
@@ -186,6 +188,8 @@ protected static class PackageListFragment extends PreferenceFragmentCompat
186188
private final static String PREF_VPN_APPLICATION_SORTBY = "pref_vpn_application_app_sortby";
187189
private final static String PREF_VPN_APPLICATION_ORDERBY = "pref_vpn_application_app_orderby";
188190

191+
private final AsyncTaskProgress task;
192+
189193
private MyApplication.VPNMode mode;
190194
private MyApplication.AppSortBy appSortBy = MyApplication.AppSortBy.APPNAME;
191195
private MyApplication.AppOrderBy appOrderBy = MyApplication.AppOrderBy.ASC;
@@ -194,6 +198,7 @@ protected static class PackageListFragment extends PreferenceFragmentCompat
194198
public PackageListFragment(MyApplication.VPNMode mode) {
195199
super();
196200
this.mode = mode;
201+
this.task = new AsyncTaskProgress(this);
197202
}
198203

199204
@Override
@@ -264,14 +269,18 @@ protected void filter(String filter, final MyApplication.AppSortBy sortBy, final
264269
storeSelectedPackageSet(selected);
265270

266271
this.removeAllPreferenceScreen();
267-
final AsyncTaskProgress task = new AsyncTaskProgress(this);
268-
task.execute("");
272+
//final AsyncTaskProgress task = new AsyncTaskProgress(this);
273+
task.execute();
269274
// this.filterPackagesPreferences(filter, sortBy, orderBy);
270275
}
271276

272277
@Override
273278
public void onPause() {
274279
super.onPause();
280+
if (this.task != null) {
281+
this.task.cancel(true);
282+
}
283+
275284
Set<String> selected = this.getAllSelectedPackageSet();
276285
storeSelectedPackageSet(selected);
277286
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MyApplication.getInstance().getApplicationContext());
@@ -475,6 +484,11 @@ public boolean onClose() {
475484
}
476485
}
477486

487+
/*
488+
* AsyncTask
489+
* https://developer.android.com/reference/android/os/AsyncTask
490+
* Deprecated in API level R
491+
* */
478492
public static class AsyncTaskProgress extends AsyncTask<String, String, List<PackageInfo>> {
479493

480494
final PackageListFragment packageFragment;
@@ -512,6 +526,11 @@ public int compare(PackageInfo o1, PackageInfo o2) {
512526
t2 = o2.packageName;
513527
break;
514528
}
529+
// try {
530+
// Thread.sleep(100);
531+
// } catch (InterruptedException e) {
532+
// e.printStackTrace();
533+
// }
515534
if (MyApplication.AppOrderBy.ASC.equals(orderBy))
516535
return t1.compareTo(t2);
517536
else
@@ -520,6 +539,7 @@ public int compare(PackageInfo o1, PackageInfo o2) {
520539
});
521540
final Map<String, Boolean> installedPackageMap = new HashMap<>();
522541
for (final PackageInfo pi : installedPackages) {
542+
if (isCancelled()) continue;
523543
// exclude self package
524544
if (pi.packageName.equals(MyApplication.getInstance().getPackageName())) {
525545
continue;

0 commit comments

Comments
 (0)