fix:修复部分手机偶现多语言切换失效问题(发现一台Vivo测试机,进入退出二级页面后,Application的Locale被重置 导致ResUtils.getString没有正确读取文本)
This commit is contained in:
@@ -14,6 +14,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.util.Supplier;
|
||||
import androidx.multidex.MultiDex;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
@@ -525,6 +526,7 @@ public class App extends BaseApp {
|
||||
BasicConfig.INSTANCE.setAppContext(this.getApplicationContext());
|
||||
SharedPreferenceUtils.init(this);
|
||||
ResUtil.init(this);
|
||||
ResUtil.contextSupplier = () -> App.gStack.getTopContext();
|
||||
LanguageHelper.INSTANCE.wrapContext(instance);
|
||||
initOtherSDK();
|
||||
initContext(this);
|
||||
|
@@ -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