Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package com.example.jetpackpromoviecatalogue.activities;
  2.  
  3. import android.content.Context;
  4. import android.content.res.Configuration;
  5. import android.os.Build;
  6.  
  7. import androidx.appcompat.app.AppCompatActivity;
  8.  
  9. import com.example.jetpackpromoviecatalogue.Preference;
  10.  
  11. import java.util.Locale;
  12.  
  13. public abstract class BaseActivity extends AppCompatActivity {
  14.     private Locale mCurrentLanguageSetting;
  15.  
  16.     @Override
  17.     protected void onStart() {
  18.         super.onStart();
  19.         Configuration config = getResources().getConfiguration();
  20.         mCurrentLanguageSetting = Build.VERSION.SDK_INT >= 24 ? config.getLocales().get(0) : config.locale;
  21.     }
  22.  
  23.     @Override
  24.     protected void onRestart() {
  25.         super.onRestart();
  26.         Locale locale = getLanguageSetting(this);
  27.  
  28.         if (!locale.equals(mCurrentLanguageSetting)) {
  29.             mCurrentLanguageSetting = locale;
  30.             recreate();
  31.         }
  32.     }
  33.  
  34.     public static Locale getLanguageSetting(Context context) {
  35.         String lang = Preference.getLanguageSetting(context);
  36.         return new Locale(lang);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement