[core] Prevent AssetManager from being GC (#1167)
This commit is contained in:
parent
1e4ffb0a17
commit
d8041f04ee
|
|
@ -58,6 +58,8 @@ public class ConfigFileManager {
|
||||||
DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(Utils.getZoneId());
|
DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(Utils.getZoneId());
|
||||||
@SuppressWarnings("FieldCanBeLocal")
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
private static FileLocker locker = null;
|
private static FileLocker locker = null;
|
||||||
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
|
private static AssetManager am = null;
|
||||||
private static Resources res = null;
|
private static Resources res = null;
|
||||||
private static ParcelFileDescriptor fd = null;
|
private static ParcelFileDescriptor fd = null;
|
||||||
|
|
||||||
|
|
@ -117,13 +119,14 @@ public class ConfigFileManager {
|
||||||
private static void loadLocale() {
|
private static void loadLocale() {
|
||||||
if (res != null) return;
|
if (res != null) return;
|
||||||
try {
|
try {
|
||||||
AssetManager am = AssetManager.class.newInstance();
|
am = AssetManager.class.newInstance();
|
||||||
//noinspection JavaReflectionMemberAccess DiscouragedPrivateApi
|
//noinspection JavaReflectionMemberAccess DiscouragedPrivateApi
|
||||||
Method addAssetPath = AssetManager.class.getDeclaredMethod("addAssetPath", String.class);
|
Method addAssetPath = AssetManager.class.getDeclaredMethod("addAssetPath", String.class);
|
||||||
addAssetPath.setAccessible(true);
|
addAssetPath.setAccessible(true);
|
||||||
addAssetPath.invoke(am, managerApkPath.toString());
|
//noinspection ConstantConditions
|
||||||
//noinspection deprecation
|
if ((int) addAssetPath.invoke(am, managerApkPath.toString()) > 0)
|
||||||
res = new Resources(am, null, null);
|
//noinspection deprecation
|
||||||
|
res = new Resources(am, null, null);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Log.e(TAG, Log.getStackTraceString(e));
|
Log.e(TAG, Log.getStackTraceString(e));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue