I have created a sample app and found that when I used stringresource to fetch the string, the composable function was called two times and In the case of LocalContext.current.getString composable function was called one time. I also tested with localization in both cases it's working. When I scanned the stringresource function internally it uses a resource composable function and it was mentioned A composable function that returns the Resources. It will be recomposed when Configuration gets updated. But if Configuration is not changed then how come it recomposes the composable function mentioned in example?
Sample Code stringresource
@Composable
fun ComposableTestWithStringResource() {
Log.d(TAG, "ComposableTestWithStringResource")
Text(
text = stringResource(id = R.string.app_name),
)
}
Sample Code LocalContext.current.getString
@Composable
fun ComposableTestWithLocalContextString() {
Log.d(TAG, "ComposableTestWithStringResource")
Text(
text = LocalContext.current.getString(R.string.app_name),
)
}