Thursday, May 31, 2012

Locale Change Receiver Android

Some times we need to know when the locale changing in our phone. We are localizing our app to be able to easily switch between languages. Everything works nicely except for some cached values that are actually in navigation. We have two options:

1. completely restart app on language change - in this case I need a notification and force restart

2. reload the activity - in this case it will require to replace string values and rebuild custom navigation state.

In both cases we need a way to find out when language switches.
In order to find out that we can use Broadcast receiver for this intent. We can use 'android.intent.action.LOCALE_CHANGED ' intent action for the same....



        
            
                
            
        
Create a receiver from Android Manifest.xml From the Receiver we will get the change in locale intent.
 
public class LocaleChangeReceiver extends BroadcastReceiver {

 @Override
 public void onReceive(Context context, Intent intent) {
  Log.i("Locale", "Changed");
 }
}

1 comment: