Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.jetpackpromoviecatalogue.activities;
- import android.content.Context;
- import android.content.res.Configuration;
- import android.os.Build;
- import androidx.appcompat.app.AppCompatActivity;
- import com.example.jetpackpromoviecatalogue.Preference;
- import java.util.Locale;
- public abstract class BaseActivity extends AppCompatActivity {
- private Locale mCurrentLanguageSetting;
- @Override
- protected void onStart() {
- super.onStart();
- Configuration config = getResources().getConfiguration();
- mCurrentLanguageSetting = Build.VERSION.SDK_INT >= 24 ? config.getLocales().get(0) : config.locale;
- }
- @Override
- protected void onRestart() {
- super.onRestart();
- Locale locale = getLanguageSetting(this);
- if (!locale.equals(mCurrentLanguageSetting)) {
- mCurrentLanguageSetting = locale;
- recreate();
- }
- }
- public static Locale getLanguageSetting(Context context) {
- String lang = Preference.getLanguageSetting(context);
- return new Locale(lang);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement