fix:修复部分手机偶现多语言切换失效问题(发现一台Vivo测试机,进入退出二级页面后,Application的Locale被重置 导致ResUtils.getString没有正确读取文本)

This commit is contained in:
max
2024-04-22 21:13:16 +08:00
parent 696dc32234
commit fc62f8cd28
2 changed files with 12 additions and 0 deletions

View File

@@ -1,18 +1,28 @@
package com.chwl.library.utils;
import android.app.Application;
import android.content.Context;
import androidx.annotation.StringRes;
import androidx.core.util.Supplier;
public class ResUtil {
private static Application context;
public static Supplier<Context> contextSupplier;
public static void init(Application context) {
ResUtil.context = context;
}
public static String getString(@StringRes int resId) {
if (contextSupplier != null) {
Context context1 = contextSupplier.get();
if (context1 != null) {
return context1.getString(resId);
}
}
return context.getString(resId);
}
}