普通類中無 `Context` 獲取 `R.string.xxx`,兩種場景:
// 工具類示例
public class StringUtils {
public static String getString(@NonNull Context context, @StringRes int resId) {
return context.getResources().getString(resId);
}
public static String getSystemString(@StringRes int systemResId) {
return Resources.getSystem().getString(systemResId);
}
}
結論:**應用資源必需 Context,系統資源可用 Resources.getSystem()**,切勿混淆。