Skip to content

Commit

Permalink
[app] Remove pending preload action when detaching (LSPosed#1006)
Browse files Browse the repository at this point in the history
Fix crash caused by preloading WebView when fragment is deteched
  • Loading branch information
canyie authored Aug 25, 2021
1 parent 6000b68 commit cc1168b
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -130,13 +131,19 @@ public void onResume() {
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(() -> {
Expand Down

0 comments on commit cc1168b

Please sign in to comment.