Prevent crash

This commit is contained in:
M66B 2021-03-10 12:01:25 +01:00
parent 55c146cf56
commit 8e909de0b6
1 changed files with 19 additions and 4 deletions

View File

@ -318,10 +318,25 @@ public class FragmentBase extends Fragment {
Log.d("Detach " + this);
super.onDetach();
InputMethodManager im = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
View focused = getActivity().getCurrentFocus();
if (focused != null)
im.hideSoftInputFromWindow(focused.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
try {
InputMethodManager im = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
View focused = getActivity().getCurrentFocus();
if (focused != null)
im.hideSoftInputFromWindow(focused.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
} catch (Throwable ex) {
Log.w(ex);
/*
Caused by: java.lang.NullPointerException: Attempt to read from field 'com.android.internal.view.IInputMethodClient com.android.server.inputmethod.InputMethodManagerService$ClientState.client' on a null object reference
at android.os.Parcel.createException(Parcel.java:2077)
at android.os.Parcel.readException(Parcel.java:2039)
at android.os.Parcel.readException(Parcel.java:1987)
at com.android.internal.view.IInputMethodManager$Stub$Proxy.hideSoftInput(IInputMethodManager.java:615)
at android.view.inputmethod.InputMethodManager.hideSoftInputFromWindow(InputMethodManager.java:1523)
at android.view.inputmethod.InputMethodManager.hideSoftInputFromWindow(InputMethodManager.java:1485)
at eu.faircode.email.FragmentBase.onDetach(SourceFile:5)
at androidx.fragment.app.Fragment.performDetach(SourceFile:3)
*/
}
}
@Override