androidsoft-org / androidsoft-coloring

Coloring for Kids
GNU General Public License v3.0
32 stars 33 forks source link

App relies on onRetainNonConfigurationInstance() always being called #5

Open dglynch opened 8 years ago

dglynch commented 8 years ago

In PaintActivity, the app relies on onRetainNonConfigurationInstance() to store important state information that cannot otherwise be recovered in the event of activity death. According to the Android SDK documentation, this method is not always guaranteed to be called, and should not be relied upon as anything other than an optimization:

http://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance()

Contrary to this, the app relies on this method always being called in order to function correctly in basic use-cases.

Whenever this method is not called by the platform (which seems to be the case when the "Don't keep activities" developer option is ticked), the following two consistent user-visible behaviours appear:

Here is a stack-trace showing the crash mentioned above:

03-26 14:50:31.335 2003-4091/? I/ActivityManager: START u0 {act=org.androidsoft.coloring.paint.START_NEW cmp=org.androidsoft.coloring/.ui.activity.StartNewActivity} from uid 10036 on display 0
03-26 14:50:31.421 2760-2760/? I/Keyboard.Facilitator: onFinishInput()
03-26 14:50:31.446 2003-2021/? I/ActivityManager: Displayed org.androidsoft.coloring/.ui.activity.StartNewActivity: +104ms
03-26 14:50:31.475 29609-29637/? D/OpenGLRenderer: endAllStagingAnimators on 0xb447d900 (RippleDrawable) with handle 0xab212250
03-26 14:50:33.240 2003-2346/? D/ConnectivityService: notifyType CAP_CHANGED for NetworkAgentInfo [WIFI () - 362]
03-26 14:50:35.062 29609-29692/? E/AndroidRuntime: FATAL EXCEPTION: Thread-10762
                                                   Process: org.androidsoft.coloring, PID: 29609
                                                   java.lang.IllegalArgumentException: width and height must be > 0
                                                       at android.graphics.Bitmap.createBitmap(Bitmap.java:829)
                                                       at android.graphics.Bitmap.createBitmap(Bitmap.java:808)
                                                       at android.graphics.Bitmap.createBitmap(Bitmap.java:775)
                                                       at org.androidsoft.coloring.ui.widget.PaintView.loadFromBitmap(PaintView.java:98)
                                                       at org.androidsoft.coloring.ui.activity.PaintActivity$InitPaintView.run(PaintActivity.java:371)
                                                       at java.lang.Thread.run(Thread.java:818)
03-26 14:50:35.065 2003-16076/? W/ActivityManager:   Force finishing activity org.androidsoft.coloring/.ui.activity.PaintActivity

I think it would be wise to implement some other more reliable means to persist outline-selection and colouring data when navigating between these three activities. While this bug is only easily reproducible when certain developer-only options are set, there is still a chance it may randomly affect an ordinary user, especially if future versions of Android ever reduce the probability of this non-guaranteed call (which is already deprecated as of API level 13). And it will definitely impact users who are handed a developer device and don't know how to (or know they need to) disable the "Don't keep activities" option.