這個泄漏發生在我的Fragment頁面銷毀的時候,我既沒有使用EditTextView,只有一個串列一個圖片和一個視頻播放View,剛看到的時候非常奇怪,我接受不了,
這個問題可能發生在不同情況下,Fragment銷毀只是一種然后找了一下網上有這么個解決方式:
protected void fixSoftInputLeaks(final Activity activity) {
//解決軟鍵盤View記憶體泄漏Google的bug
if (activity == null) return;
InputMethodManager imm =
(InputMethodManager) AppUtils.getApp().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null) return;
String[] leakViews = new String[]{"mLastSrvView", "mCurRootView", "mServedView", "mNextServedView"};
for (String leakView : leakViews) {
try {
Field leakViewField = InputMethodManager.class.getDeclaredField(leakView);
if (leakViewField == null) continue;
if (!leakViewField.isAccessible()) {
leakViewField.setAccessible(true);
}
Object obj = leakViewField.get(imm);
if (!(obj instanceof View)) continue;
View view = (View) obj;
if (view.getRootView() == activity.getWindow().getDecorView().getRootView()) {
leakViewField.set(imm, null);
}
} catch (Throwable ignore) { /**/ }
}
}
只需要在你的發生泄露的Fragment或者在Activity的onDestroy中呼叫此方法即可,
看代碼描述這應該是Google的bug,特此記錄,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/107049.html
標籤:其他
下一篇:android記憶體泄漏
