fix:修复部分手机偶现多语言切换失效问题(发现一台Vivo测试机,进入退出二级页面后,Application的Locale被重置 导致ResUtils.getString没有正确读取文本)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user