How to change the language with a button in Android Studio
<p>Please assist,</p>

<p>I have created two addition language resource and would like to give the game the option to change the language option with a button selection.</p>

<p>I created a class called LocaleHelper which I found via google as per below however the locale has since been depricated. How to go about now?</p>

<pre><code>    package biz.myecard.mathisfun;

/**
 * Created by Hans Fouche on 2016/10/18.
 */

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.preference.PreferenceManager;

import java.util.Locale;

public class LocaleHelper {

    private static final String SELECTED_LANGUAGE = "Locale.Helper.Selected.Language";

    public static void onCreate(Context context) {
        String lang = getPersistedData(context, Locale.getDefault().getLanguage());
        setLocale(context, lang);
    }

    public static void onCreate(Context context, String defaultLanguage) {
        String lang = getPersistedData(context, defaultLanguage);
        setLocale(context, lang);
    }

    public static String getLanguage(Context context) {
        return getPersistedData(context, Locale.getDefault().getLanguage());
    }

    public static void setLocale(Context context, String language) {
        persist(context, language);
        updateResources(context, language);
    }

    private static String getPersistedData(Context context, String defaultLanguage) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        return preferences.getString(SELECTED_LANGUAGE, defaultLanguage);
    }

    private static void persist(Context context, String language) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = preferences.edit();

        editor.putString(SELECTED_LANGUAGE, language);
        editor.apply();
    }

    private static void updateResources(Context context, String language) {
        Locale locale = new Locale(language);
        Locale.setDefault(locale);

        Resources resources = context.getResources();

        Configuration configuration = resources.getConfiguration();
        configuration.locale = locale;

        resources.updateConfiguration(configuration, resources.getDisplayMetrics());
    }
}
</code></pre>

<p>It is the called in the button method with:</p>

<pre><code>LocaleHelper.onCreate(this, "en");
</code></pre>

<p><strong>Error as below:</strong> My APP works but don't thinks this is optimal.</p>

<p>Note: /Users/macintoshhd/Desktop/AndroidCourse/MathisFun/app/src/main/java/biz/myecard/mathisfun/LocaleHelper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.</p>