Android AssetManager.finalize()
2020-02-18 本文已影响0人
周_0717
这类错误是由于回收对象时间过长,由FinalizerWatchdogDaemon负责计时,超时后抛出异常关闭VM的。使用关闭计时器的方式避免崩溃发生
private fun fixAssetManager() {
val device = Build.BRAND + " " + Build.MODEL
if (!TextUtils.isEmpty(device)) {
if (device.contains("OPPO R9") || device.contains("OPPO A5") || device.contains("OPPO A3")
|| device.contains("OPPO R7") || device.contains("360 180") || device.contains("LE X8")) {
try {
// 关闭掉FinalizerWatchdogDaemon
val clazz = Class.forName("java.lang.Daemons\$FinalizerWatchdogDaemon")
val method = clazz.superclass!!.getDeclaredMethod("stop")
method.isAccessible = true
val field = clazz.getDeclaredField("INSTANCE")
field.isAccessible = true
method.invoke(field.get(null))
} catch (e: Throwable) {
e.printStackTrace()
}
}
}
}