-
Notifications
You must be signed in to change notification settings - Fork 197
Fix: getConfiguration().locale field was deprecated in API level 24 + example fix #29
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, good point. Done.
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...