hanjing 7 éve
szülő
commit
93d5f2dffa

+ 31 - 10
app/src/main/java/com/sheep/gamegroup/absBase/BaseActivity.java

@@ -6,7 +6,6 @@ import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.support.v7.app.ActionBar;
 import android.support.v7.widget.Toolbar;
-import android.util.Log;
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
@@ -153,7 +152,7 @@ public abstract class BaseActivity extends RxAppCompatActivity {
 
     @Override
     protected void onDestroy() {
-//        fixHuaweiLeak();
+        fixInputMethodLeak();
         try {
             if (needButterKnife() && this.unbinder != null) {
                 this.unbinder.unbind();
@@ -168,11 +167,12 @@ public abstract class BaseActivity extends RxAppCompatActivity {
 
 
     //解决华为手机内存泄漏问题
-    private static Field[] leakFields = new Field[2];
-    private static boolean[] hasLeakFields = {true, true};
-    private static String[] leakFieldNames = {"mLastSrvView", "mNextServedView"};
+    private static Field[] leakFields = new Field[1];
+    private static boolean[] hasLeakFields = {true};
+    private static String[] leakFieldNames = {"mLastSrvView"};
+//    private static String[] leakFieldNames = {"mLastSrvView", "mNextServedView"};
 
-    private void fixHuaweiLeak() {
+    private void fixInputMethodLeak() {
         boolean goon = false;
         for (boolean has : hasLeakFields) {
             goon = goon || has;
@@ -195,10 +195,15 @@ public abstract class BaseActivity extends RxAppCompatActivity {
                 }
                 if (leakFields[i] != null) {
                     leakFields[i].setAccessible(true);
-                    Object obj = leakFields[i].get(imm);
-                    View view = (View) obj;
-                    Log.e("Leak", leakFieldNames[i]+": "+view.getContext().getClass().getSimpleName()+" - " +getClass().getSimpleName());
-//                    leakFields[i].set(imm, null);
+//                    Object obj = leakFields[i].get(imm);
+//                    View view = (View) obj;
+//                    Log.e("Leak", leakFieldNames[i] +
+//                            " : " + view.getClass().getSimpleName() +
+//                            " = " + view.getContext().getClass().getSimpleName() +
+//                            " (" + view.getContext().hashCode() + ")" +
+//                            " - " + getClass().getSimpleName()+
+//                            " (" + this.hashCode() + ")");
+                    leakFields[i].set(imm, null);
                 }
             } catch (Throwable t) {
                 t.printStackTrace();
@@ -206,6 +211,22 @@ public abstract class BaseActivity extends RxAppCompatActivity {
         }
     }
 
+    public void releaseInputMethodRefView() {
+        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
+        if (imm == null) {
+            return;
+        }
+        try {
+            Field field = imm.getClass().getDeclaredField("mNextServedView");
+            if (field != null) {
+                field.setAccessible(true);
+                field.set(imm, null);
+            }
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+
     public void hideSystemStatusBar() {
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                 WindowManager.LayoutParams.FLAG_FULLSCREEN);

+ 18 - 4
app/src/main/java/com/sheep/gamegroup/view/activity/ActMain.java

@@ -7,6 +7,7 @@ import android.support.annotation.Nullable;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentTransaction;
 import android.text.TextUtils;
+import android.transition.Transition;
 import android.view.MotionEvent;
 import android.view.View;
 import android.widget.FrameLayout;
@@ -139,7 +140,7 @@ public class ActMain extends BaseActYmPermissionCheck {
 //        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && G.checkDeviceHasNavigationBar(this)) {
 //            main_layout.setPadding(0, 0, 0, G.getHasVirtualKey(this) - G.getNoHasVirtualKey(this));
 //        }
-
+//todo///////////////////////////////////////////////////////////////////////////////////////////
         CommonUtil.getInstance().initMiDong(this, DataUtil.getInstance().getUserId());
     }
 
@@ -171,10 +172,10 @@ public class ActMain extends BaseActYmPermissionCheck {
                 fragment = mainTabs[index].getFragment();
             }
             fragmentList.add(fragment);
-            transaction.add(R.id.frame_container, fragment, "fragment_"+index);
-            if(index==0) {
+            transaction.add(R.id.frame_container, fragment, "fragment_" + index);
+            if (index == 0) {
                 transaction.show(fragment);
-            }else{
+            } else {
                 transaction.hide(fragment);
             }
             View view = tab_container.getChildAt(index * 2 + 1);
@@ -246,6 +247,19 @@ public class ActMain extends BaseActYmPermissionCheck {
      */
     private void doBackPress() {
         if (System.currentTimeMillis() - mLastBackTime < 1000) {
+            fragmentList.clear();
+            fragmentList = null;
+            fragmentList = getSupportFragmentManager().getFragments();
+            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+            for (Fragment fragment : fragmentList) {
+                try {
+                    transaction.remove(fragment);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+            transaction.commitAllowingStateLoss();
+            releaseInputMethodRefView();
             SheepApp.getInstance().quit();
             finish();
         } else {