Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.view.inputmethod.InputMethodManager; import java.lang.reflect.Field; public class Main { public static void fixInputMethodManagerLeak(Context context) { if (context == null) { return; } try { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm == null) { return; } Field f_mCurRootView = imm.getClass().getDeclaredField("mCurRootView"); Field f_mServedView = imm.getClass().getDeclaredField("mServedView"); Field f_mNextServedView = imm.getClass().getDeclaredField("mNextServedView"); f_mCurRootView.setAccessible(true); f_mCurRootView.set(imm, null); f_mServedView.setAccessible(true); f_mServedView.set(imm, null); f_mNextServedView.setAccessible(true); f_mNextServedView.set(imm, null); } catch (Throwable t) { t.printStackTrace(); } } }