The analysis of this kind of problem is generally needed to find the bitmap object in that location has been recyle, and then check the code.
How to navigate to which code location has the Bitmap object Recyle, in the Bitmap.java recycle method, add log to print out the call stack to locate.
The specific modifications are as follows:
public void Recycle () {
if (!mrecycled) {
if (Nativerecycle (Mnativebitmap)) {
Return value indicates whether native pixel object was actually recycled.
False indicates that it's still in with the native level and these
Objects should not being collected now. They'll be collected later when the
Bitmap itself is collected.
Mbuffer = null;
Mninepatchchunk = null;
}
Mrecycled = true;
LOG.E ("Bitmap recyle!", "this =" + This, new Throwable ("recycle"));
}
}
The bitmap object is then printed out where it throws java.lang.IllegalArgumentException:Cannot draw recycled bitmaps anomalies. The mobile log analysis that captures the recurrence problem.
For example, the following log:
Search for "FATAL EXCEPTION" in main log to see the following trace of FATAL error EXCEPTION, corresponding bitmap object [email protected]
01-01 08:03:23.841 2369 2369 D androidruntime:shutting down VM
01-01 08:03:23.841 2369 2369 W dalvikvm:threadid=1:thread exiting with uncaught exception (GROUP=0X40F979A8)
01-01 08:03:23.856 2369 2369 E androidruntime:fatal exception:main
01-01 08:03:23.856 2369 2369 E AndroidRuntime:java.lang.IllegalArgumentException:Cannot Draw recycled [email protected ]
Then search the main log for the keyword "@4218d0c8", you can see the object is Recyle call stack
01-01 08:03:22.741 2369 2369 E bitmap recyle! : this = [email protected]
01-01 08:03:22.741 2369 2369 E bitmap recyle! : java.lang.Throwable:recycle
01-01 08:03:22.741 2369 2369 E bitmap recyle! : At Android.graphics.Bitmap.recycle (bitmap.java:214)
01-01 08:03:22.741 2369 2369 E bitmap recyle! : At Com.xxx.xxxx.xxxActivity.onDestroy (xxxactivity.java:190)
01-01 08:03:22.741 2369 2369 E bitmap recyle! : At Android.app.Fragment.performDestroy (fragment.java:1908)
......
How Android analyzes Java.lang.IllegalArgumentException:Cannot draw recycled bitmaps exception