The way we did this was to use translations:
- Send a broadcast every time a user changes their language.
- Register the broadcast receiver in
AppActivity.onCreate() and unregister in AppActivity.onDestroy() - In
BroadcastReceiver.onReceive() just restart the action.
AppActivity is a parent activity that applies to all other activity subclasses.
Below is a snippet of my code that was not tested outside the project, but should give you a good idea.
When a user changes language
sendBroadcast(new Intent("Language.changed"));
And in parental activity
public class AppActivity extends Activity { private BroadcastReceiver mLangaugeChangedReceiver; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState);
It will also update the activity that changed the language (if it subclasses the above action).
This will lead to the loss of any data, but if it is important, you should have already taken care of this with Actvity.onSaveInstanceState() and Actvity.onRestoreInstanceState() (or the like).
Let me know your thoughts on this.
Hurrah!
Sabo Apr 7 '15 at 10:08 2015-04-07 10:08
source share