|
|
@@ -27,6 +27,7 @@ import android.view.ViewGroup;
|
|
|
import android.view.Window;
|
|
|
import android.view.WindowManager;
|
|
|
import android.view.animation.AccelerateInterpolator;
|
|
|
+import android.view.inputmethod.InputMethodManager;
|
|
|
import android.widget.FrameLayout;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
@@ -46,6 +47,7 @@ import com.yalantis.ucrop.view.widget.HorizontalProgressWheelView;
|
|
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
@@ -640,4 +642,45 @@ public class UCropActivity extends AppCompatActivity {
|
|
|
setResult(UCrop.RESULT_ERROR, new Intent().putExtra(UCrop.EXTRA_ERROR, throwable));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onDestroy(){
|
|
|
+ fixInputMethodLeak();
|
|
|
+ super.onDestroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ //解决华为手机内存泄漏问题
|
|
|
+ private void fixInputMethodLeak() {
|
|
|
+ Field[] leakFields = new Field[1];
|
|
|
+ boolean[] hasLeakFields = {true};
|
|
|
+ String[] leakFieldNames = {"mLastSrvView"};
|
|
|
+ boolean goon = false;
|
|
|
+ for (boolean has : hasLeakFields) {
|
|
|
+ goon = goon || has;
|
|
|
+ if (goon) break;
|
|
|
+ }
|
|
|
+ if (!goon) return;
|
|
|
+
|
|
|
+ InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
|
|
|
+ if (imm == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < leakFieldNames.length; i++) {
|
|
|
+ try {
|
|
|
+ if (leakFields[i] == null) {
|
|
|
+ leakFields[i] = imm.getClass().getDeclaredField(leakFieldNames[i]);
|
|
|
+ }
|
|
|
+ if (leakFields[i] == null) {
|
|
|
+ hasLeakFields[i] = false;
|
|
|
+ }
|
|
|
+ if (leakFields[i] != null) {
|
|
|
+ leakFields[i].setAccessible(true);
|
|
|
+ leakFields[i].set(imm, null);
|
|
|
+ }
|
|
|
+ } catch (Throwable t) {
|
|
|
+ t.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|