Fix: getConfiguration().locale field was deprecated in API level 24 + example fix#29
Fix: getConfiguration().locale field was deprecated in API level 24 + example fix#29janstol wants to merge 3 commits intorxlabz:masterfrom
Conversation
vintage
left a comment
There was a problem hiding this comment.
Thanks, looks good! Just one comment about reusing the code.
| Locale locale = activity.getResources().getConfiguration().locale; | ||
| Locale locale; | ||
| if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { | ||
| locale = activity.getResources().getConfiguration().getLocales().get(0); |
There was a problem hiding this comment.
How about moving the part activity.getResources().getConfiguration() outside of conditional statements to avoid code repetition? We would have something like:
Configuration config = activity.getResources().getConfiguration();
Locale locale;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
locale = config.getLocales().get(0);
} else {
locale = config.locale;
}
|
Just tested the changes on Android 9 (OnePlus 6t) - works as expected. As it's always good to be aligned with the deprecations of the platforms, @rxlabz can you give it a look? |
|
package com.example.newgenrationdairy; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import java.util.Locale; public class test extends AppCompatActivity { } i have a problem with config.locale = locale; help me |
Configuration.locale
Also updated (fixed) example...