'How to globally change language in Android app

I have such code, and its work fine, but it change language only in context which was applied. I need to run this code in all activities. How can i change language in all app? I run this code in MainActivity.

Locale locale = new Locale(language);
        Locale.setDefault(locale);
        Resources resources = context.getResources();
        Configuration configuration = resources.getConfiguration();
        context.createConfigurationContext(configuration);
        configuration.locale = locale;
        resources.updateConfiguration(configuration, resources.getDisplayMetrics());

        return true;

I took this code from answer on question: Language not changing in app Android Studio



Solution 1:[1]

I don't think there is an answer that would fit here because what you're asking is essentially supporting multiple languages for an app. I recommend searching youtube for tutorials or if you have no problem reading the official documentation then the the Android Developer website is probably you best bet.

Solution 2:[2]

It's better if you have BaseActivity class and In that class override method attachBaseContext() which sends a Context object which can be used in the activity.

override fun attachBaseContext(newBase: Context) { super.attachBaseContext(LangContextWrapper.wrap(newBase, LangManager.currentLang)) }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mark
Solution 2 Dev Rawayzan