android app screen flashing at launch android app screen flashing at launch android android

android app screen flashing at launch


FINALLY FOUND THE ERROR AND THE PROPER SOLUTION !!

Actually, The problem occurred only when people first launched the App from a screen on land mode... The App is forced to be portrait in the Manifest, but, nevertheless, I realised that Android still executes the onConfigurationChanged at launch (when passing from Land to Portrait, e.g)

The problem is that the App is in 2 languages and to keep the right language on screen orientation I had increment my own Myapplication (to extend Application) to manage onConfigurationChanged and set the correct Locale default throughout the App!!

Even after forcing the App to Portrait in the Manifest (for some reasons some time ago), the onConfigurationChanged from MyApplication.java was still executed in some circomstances...

THE PROBLEM :

The code in the MyApplication.java was

public void onConfigurationChanged(Configuration newConfig)  {      super.onConfigurationChanged(newConfig);      // Set correct language (default or chosen)      Locale locale = new Locale(getState());       Locale.setDefault(locale);      newConfig.locale = locale;      getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());  }

THE SOLUTION:

Do not use directly newConfig, but make a Modifiable Configuration object, instead, as adviced by Android Developper, and work with it

public void onConfigurationChanged(Configuration newConfig)  {      super.onConfigurationChanged(newConfig);      // Set correct language (default or chosen)      Locale locale = new Locale(getState());       Locale.setDefault(locale);      Configuration config = new Configuration(newConfig); // get Modifiable Config from actual config changed      config.locale = locale;      getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());  }

The former solution to load directly the newConfog objest was working until Android v2.3 but was not accepted any more in the Android Version >= 4.0

EVERYTHING IS OK NOW !!

(Special Thanks to Frédéric Espiau alias Apollidore, as the solution came reading his excellent book "Créez des applications pour Android")