[app] Remove pending preload action when detaching (#1006)
Fix crash caused by preloading WebView when fragment is deteched
This commit is contained in:
parent
6000b68f75
commit
cc1168bad9
|
|
@ -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(() -> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue