Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Runtime Development

Reply
New Contributor
jugos654
Posts: 2
Registered: ‎04-24-2013
My Device: BB Playbook 2.1
My Carrier: t-mobile

Porting android to BB Change of language problems...

Hi, I developed multilanguage app for Android, so i Need to port to BB PlayBook and BB10

I am testing the app on the playbook and I have this problem:

It is about english and arabic language, It seems like when I change the language, only then the arabic is shown correctly and the correct strings.xml.

The next run of the app it reads the set language from the SharedPreferences file and it sets the language in the onCreate in mainActivity, aligns the text to the right BUT displays the english strings.xml. 

In the mainActivity is used the same code that i use for the changing the language in languageActivity.

 

Now if I change it to ar again manually it will change!!!!!!

and that is repeating every time I run the app.


Here is the code for changing the language:

SharedPreferences mSharedPrefs = getSharedPreferences("xmlFile",Context.MODE_PRIVATE);
Configuration conf = getResources().getConfiguration();
String language = mSharedPrefs.getString("language", "en"); // "en" is the default value if no other found 
Locale locale = new Locale(language);
Locale.setDefault(locale);
conf.locale = locale;
this.getBaseContext().getResources().updateConfiguration(conf, getResources().getDisplayMetrics());

SharedPreferences.Editor mPrefsEditor = mSharedPrefs.edit();

mPrefsEditor.putString("language", language);
mPrefsEditor.commit();

Is there someone that has any kind of idea why is this happening???

 

I would be very gratefull 

Please use plain text.
New Contributor
jugos654
Posts: 2
Registered: ‎04-24-2013
My Device: BB Playbook 2.1
My Carrier: t-mobile

Re: Porting android to BB Change of language problems...

[ Edited ]

ANYONE???!?

Please use plain text.
New Developer
secbbm
Posts: 9
Registered: ‎06-23-2013
My Device: BB Z10
My Carrier: STC

Re: Porting android to BB Change of language problems...

----------global class so that can be called from any activity

class GlobalClass{
SharedPreferences preferences;
 

public static void ChangeLanguage(){
preferences = PreferenceManager.getDefaultSharedPreferences(context);
String language = preferences.getString("language", "ar");
Locale appLoc = new Locale(language );
Locale.setDefault(appLoc);
Configuration appConfig = new Configuration();
appConfig.locale = appLoc;
c.getResources().updateConfiguration(appConfig, c.getResources().getDisplayMetrics());
}
}

 

----------Activity class
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 GlobalClass.ChangeLanguage();
}

Please use plain text.