Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screen flickers when running on Android 4.2. (Activity gets restarted continuously)

Some users reported that my app screen sometimes flickers when running on Android 4.2 (only!)

I tried on my device, and after putting logs, the activity is restarted and restarted again, about 3 times a second.

So what I did is to trace the method calls when it restarts continually, and here is the result:

method trace output

It seems that the problem lies in the ViewGroup.resetRtlProperties(), since this is new in Android 4.2 (17).

I can't confirm yet if this is a bug, but is there anyone else experiencing this or have any workarounds?

like image 265
Randy Sugianto 'Yuku' Avatar asked Nov 19 '12 05:11

Randy Sugianto 'Yuku'


People also ask

Why is my phone screen flickering Android?

It's possible that the display problem you're facing might have spawned from a messy software build. Usually, a simple software update fixes the issue, so check if there's an update available for your device. To check your software version on Android, go to Settings > System > System update.

What causes screen flickering?

If all monitors, or your only monitor, flickers, it is worth checking out the hardware and connections. Check that your graphics card does not have accumulated dirt and dust on the surfaces. Make sure the cooling fan is working and that all case fans are turning when they should.


2 Answers

I had a similar problem and it was caused by a combination of the following two:

  • An activity in landscape orientation (while the device preferred portrait)
  • Code in onConfigurationChanged() of the Application subclass that changed the locale of the newConfig parameter

Instead of changing newConfig you can clone that object and change/use the clone:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Configuration configClone = new Configuration(newConfig);
    // Change/use configClone here
    ...
}
like image 129
Adam Nybäck Avatar answered Sep 20 '22 17:09

Adam Nybäck


Apparently, adding layoutDirection to the list of android:configChanges of your <activity> in the AndroidManifest.xml fixed this problem.

like image 28
Randy Sugianto 'Yuku' Avatar answered Sep 18 '22 17:09

Randy Sugianto 'Yuku'