3

I have all activities inherit from my BaseActivity. It's been working great for a year. Now after I upgraded my Nexus S to 4.0.3 my app stopped working - I get infinite loop that look like so:

12-28 20:09:22.285: DEBUG/IDATT.HomeActivity(24662): onCreate
12-28 20:09:22.285: DEBUG/IDATT.BaseActivity(24662): onCreate
12-28 20:09:22.442: DEBUG/IDATT.HomeActivity(24662): onResume
12-28 20:09:22.442: DEBUG/IDATT.BaseActivity(24662): onResume
12-28 20:09:22.578: DEBUG/IDATT.HomeActivity(24662): onCreate
12-28 20:09:22.578: DEBUG/IDATT.BaseActivity(24662): onCreate
12-28 20:09:22.653: DEBUG/IDATT.HomeActivity(24662): onResume
12-28 20:09:22.653: DEBUG/IDATT.BaseActivity(24662): onResume
12-28 20:09:22.785: DEBUG/IDATT.HomeActivity(24662): onCreate
12-28 20:09:22.785: DEBUG/IDATT.BaseActivity(24662): onCreate
12-28 20:09:22.863: DEBUG/IDATT.HomeActivity(24662): onResume
12-28 20:09:22.863: DEBUG/IDATT.BaseActivity(24662): onResume

So, when HomeActivity started it calls base.onCreate which is second line. Then onResume called and for some reason after that - BaseActivity.onCreate called again.

Does this make sense? One thing I noticed is that everything runs OK until I turn screen. Then it starts blinking. Even if I hit Home and open application again. But if I kill process and restart it looks good until I try to flip screen again..

EDIT: I removed all the code samples - they not relevant. Seems like I found my issue. I did override onConfigurationChange in my Application

@Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        Log.d(LOG_TAG, "onConfigurationChanged");
        super.onConfigurationChanged(newConfig);

        //reset locale to our defined locale in settings
//        String l = Preferences.getLocale(getApplicationContext());
//        Locale locale = new Locale(l);
//        if (!l.equals(""))
//        {
//            newConfig.locale = locale;
//            Locale.setDefault(locale);
//            getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
//        }
    }

Commented code caused issue. Seems like doing what I did (to change locale) caused whole UI to restart and it was doing it repeatedly. Now I need to come up with better way.

So, there is breaking change in this Locale area in 4.0

katit
  • 17,375
  • 35
  • 128
  • 256
  • 2
    Show your `onCreate(...)` and `onResume()` code of both `BasActivity` and `HomeActivity`. – Squonk Dec 29 '11 at 02:04
  • There is a lot of code, I tried commenting most of it with no change.. – katit Dec 29 '11 at 02:14
  • I've never used `updateConfiguration(...)` but that suggests to me it's going to trigger `onConfigurationChanged(...)`. No? If it does, that's where your infinite loop is coming from. What happens if you leave the call to `updateConfiguration(...)` commented out, uncomment the other lines and move `super.onConfigurationChanged(newConfig);` to the end of your overridden `onConfigurationChanged(...)` method. In other words, call it last after you have modified `newConfig` to set its locale. – Squonk Dec 29 '11 at 03:35
  • Yes, it makes sense. But this issue just now started with 4.0 This code is bad anyway. I will try to see if I can get rid of it alltogether. – katit Dec 29 '11 at 03:56
  • OK - sorry I can't help further. As I said, it's not something I've done in any of my own code. Good luck in finding a solution. – Squonk Dec 29 '11 at 05:08
  • Have you resolved this issue? I'm experiencing the same now. – Mikhail Mar 13 '13 at 12:03
  • Yes, it is in main post – katit Mar 13 '13 at 13:54
  • A better solution is here: http://stackoverflow.com/questions/15406345/activity-is-blinking-after-locale-change-in-android-4-1 – Martin Nov 09 '13 at 13:12

2 Answers2

2

Try to edit AndroidManifest.xml and add android:configChanges="locale" for all activities. It can fix the re-create problem.

Sam Lu
  • 3,448
  • 1
  • 27
  • 39
  • Unfortunately this did not work for me but I found a solution here:http://stackoverflow.com/questions/15406345/activity-is-blinking-after-locale-change-in-android-4-1 – Martin Nov 09 '13 at 13:13
0

android:configChanges="locale" saved me some real pain. I was getting an endless pause/resume loop but only on pre ics devices, and only after i downloaded the sdks for jellybean.

Aiden Fry
  • 1,672
  • 3
  • 21
  • 45