|
|
@@ -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);
|