[app] Remove pending preload action when detaching (#1006)

Fix crash caused by preloading WebView when fragment is deteched
This commit is contained in:
残页 2021-08-25 22:18:49 +08:00 committed by GitHub
parent 6000b68f75
commit cc1168bad9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -66,6 +66,7 @@ public class RepoFragment extends BaseFragment implements RepoLoader.Listener {
protected FragmentRepoBinding binding;
protected SearchView searchView;
private SearchView.OnQueryTextListener mSearchListener;
private Handler mHandler = new Handler(Looper.getMainLooper());
private boolean preLoadWebview = true;
private final RepoLoader repoLoader = RepoLoader.getInstance();
@ -130,13 +131,19 @@ public class RepoFragment extends BaseFragment implements RepoLoader.Listener {
super.onResume();
adapter.initData();
if (preLoadWebview) {
new Handler(Looper.getMainLooper()).postDelayed(() -> {
if (!isRemoving()) new WebView(requireContext());
mHandler.postDelayed(() -> {
new WebView(requireContext());
}, 500);
preLoadWebview = false;
}
}
@Override
public void onDetach() {
mHandler.removeCallbacksAndMessages(null);
super.onDetach();
}
@Override
public void repoLoaded() {
requireActivity().runOnUiThread(() -> {