@@ -214,8 +214,6 @@ protected void onDestroy() {
214214 WaitingDialog .dismissAndRelease (mWaitingDialog );
215215 mWaitingDialog = null ;
216216 super .onDestroy ();
217- // fixHuaWeiMemoryLeak();
218- // fixInputMethodManagerLeak(this);
219217 }
220218
221219
@@ -227,67 +225,4 @@ protected void hideSoftInput() {
227225 imm .hideSoftInputFromWindow (getWindow ().getDecorView ().getWindowToken (), 0 );
228226 }
229227
230- /**
231- * 修复华为手机内存的泄露
232- */
233- public void fixHuaWeiMemoryLeak (){
234- //测试
235- try {
236- Class <?> GestureBoostManagerClass = Class .forName ("android.gestureboost.GestureBoostManager" );
237- Field sGestureBoostManagerField = GestureBoostManagerClass .getDeclaredField ("sGestureBoostManager" );
238- sGestureBoostManagerField .setAccessible (true );
239- Object gestureBoostManager = sGestureBoostManagerField .get (GestureBoostManagerClass );
240- Field contextField = GestureBoostManagerClass .getDeclaredField ("mContext" );
241- contextField .setAccessible (true );
242- if (contextField .get (gestureBoostManager )==this ) {
243- contextField .set (gestureBoostManager , null );
244- }
245- } catch (Throwable t ) {
246- // t.printStackTrace();
247- // 忽略该异常
248- }
249-
250- }
251-
252- /**
253- * 修复InputMethodManager导致Activity的内存泄露<br/>
254- * 问题链接:http://blog.csdn.net/sodino/article/details/32188809
255- * @param destContext
256- */
257- private void fixInputMethodManagerLeak (Context destContext ) {
258- if (destContext == null ) {
259- return ;
260- }
261-
262- InputMethodManager imm = (InputMethodManager ) destContext .getSystemService (Context .INPUT_METHOD_SERVICE );
263- if (imm == null ) {
264- return ;
265- }
266-
267- String [] arr = new String []{"mLastSrvView" ,"mCurRootView" , "mServedView" , "mNextServedView" };
268- Field f = null ;
269- Object obj_get = null ;
270- for (int i = 0 ; i < arr .length ; i ++) {
271- String param = arr [i ];
272- try {
273- f = imm .getClass ().getDeclaredField (param );
274- if (!f .isAccessible ()) {
275- f .setAccessible (true );
276- }
277- obj_get = f .get (imm );
278- if (obj_get != null && obj_get instanceof View ) {
279- View v_get = (View ) obj_get ;
280- if (v_get .getContext () == destContext ) { // 被InputMethodManager持有引用的context是想要目标销毁的
281- f .set (imm , null ); // 置空,破坏掉path to gc节点
282- } else {
283- // 不是想要目标销毁的,即为又进了另一层界面了,不要处理,避免影响原逻辑,也就不用继续for循环了
284- break ;
285- }
286- }
287- } catch (Throwable t ) {
288- // t.printStackTrace();
289- }
290- }
291- }
292-
293228}
0 commit comments