How can I update attachBaseContext in MainActivity from a fragment? E.g.
MyFragment.java
String chosenLanguage = "en";
public void updateLanguage(String chosenLanguage) {
//...Update MyContextWrapper.wrap(newBase, chosenLanguage) here
}
MainActivity.java (Following succesfully calls a java class and changes app language)
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(MyContextWrapper.wrap(newBase,"en"));
}
You need to restart activity to run 'attachBaseContext' again.
In your fragment run:
Intent intent= new Intent(getContext(), MainActivity.class); startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With