android.content.res.AssetManager.finalize() timed out after 120 seconds

异常问题:

android.content.res.AssetManager.finalize() timed out after 120 seconds
android.content.res.AssetManager.finalize() timed out after 120 seconds_第1张图片

主要发生在OPPO R9和A5的手机;

解决方式有两种:

1、关掉这个负责计时的

private void fixOppoAssetManager() {
        String device = AppUtils.getDeviceInfo();
        if (!TextUtils.isEmpty(device)) {
            if (device.contains("OPPO R9") || device.contains("OPPO A5")) {
                try {
                    // 关闭掉FinalizerWatchdogDaemon
                    Class clazz = Class.forName("java.lang.Daemons$FinalizerWatchdogDaemon");
                    Method method = clazz.getSuperclass().getDeclaredMethod("stop");
                    method.setAccessible(true);
                    Field field = clazz.getDeclaredField("INSTANCE");
                    field.setAccessible(true);
                    method.invoke(field.get(null));
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }

2、延长计时时间

private void fixOppoAssetManager() {
        String device = AppUtils.getDeviceInfo();
        if (!TextUtils.isEmpty(device)) {
            if (device.contains("OPPO R9") || device.contains("OPPO A5")) {
                try {
                    Class<?> c = Class.forName("java.lang.Daemons");
    Field maxField = c.getDeclaredField("MAX_FINALIZE_NANOS");
    maxField.setAccessible(true);
    maxField.set(null, Long.MAX_VALUE);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

然后在Application中重写attachBaseContext()方法

@Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
        fixOppoAssetManager();
    }

你可能感兴趣的:(Android中遇到的那些问题)