Previously on Frozen Frames story i tell a story about how to find and fixing Rendering Performance Issues (Slow Rendering and ANR).
This time i called Rendering Issues as ANR (Android Not Responding) issues.
Once you fixed ANR be aware of CRASH.
ANR Problem
Code above explain that function initBitrate
running on Main Thread. And inside initBitrate there is 1 line code that access diskAndroid SharedPreference
. Which is this should be running on other Thread.
Fixing the ANR Issue
Code above explain that i move init bitrate into other Thread. and the ANR issue has solved.
New Problem
I got a new crash issue. that caused by ANR issue fixing.
On that log, we found that i access List that at the other Thread that list got update. That causing Illegal State Exception.
Fixing The Crash
So now i try to fix the crash without causing ANR anymore.
Short story.. i fix the crash with RX Java. I make sure the accessing and modify List object at the same Thread.
Conclusion
Sometimes if you want to fix ANR issues, fix carefully, Its not just move Thread from UI Thread to other Thread, but be aware of possibility Crash Issues.
at java.lang.Thread.run (Thread.java:764)