Why don't you take out the recycle() calls altogether and see if it works?


Even if you assign after recycling, the following could happen:



*bitmap.recycle();*

*
*

*----  thread switch  ----*

*
*

*other thread tries to use bitmap*




On Monday, March 18, 2013 12:50:37 PM UTC-5, Marina Cuello wrote:
>
> Hi!
> I'm having a weird problem with one of my apps. I'll try later to extract 
> some code and make a sample project to share if it's useful but by now I'm 
> just asking  to see if anyone found this one or can give me a hint on how 
> to tackle it.
>
> I have two activities. 
>
> Activity A extends SherlockActivity from ActionBarSherlock and haves a 
> GridView on it. The grid items have an ImageButton. When you press on the 
> ImageButton, it calls an instance of Activity B.
>
> Activity B extends SherlockFragmentActivity (ActionBarSherlock again), 
> with a ViewPager on it. The fragments have a very complex layout.
>
> My Activity B has a menu with only one item. The item is set-up on 
> onOptionsItemSelected so it simply calls "onBackPressed()". That one  calls 
> "super.onBackPressed()" right away. I've only overridden it for debugging 
> purposes.
>
> I tested it on some Jelly Bean devices and on a couple Gingerbread ones 
> (I'm using some co-workers phones as test devices :)). On Jelly Bean it's 
> ok. But in Gingerbread I've met a weird behaviour.
>
> When I'm on B, and press the back button on the device, it closes B and 
> goes normally to A. But, if I press the option on the menu, I've got a 
> "force close" message and I've got the following log:
>
> java.lang.RuntimeException: Canvas: trying to use a recycled bitmap 
> android.graphics.Bitmap@2b021388
> at android.graphics.Canvas.throwIfRecycled(Canvas.java:955)
>  at android.graphics.Canvas.drawBitmap(Canvas.java:1044)
> at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:325)
>  at android.widget.ImageView.onDraw(ImageView.java:881)
> at android.view.View.draw(View.java:6986)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.View.draw(View.java:6989)
> at android.widget.FrameLayout.draw(FrameLayout.java:361)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.View.draw(View.java:6989)
> at android.widget.FrameLayout.draw(FrameLayout.java:361)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.View.draw(View.java:6989)
> at android.support.v4.view.ViewPager.draw(ViewPager.java:1923)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1739)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.ViewGroup.drawChild(ViewGroup.java:1737)
> at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1466)
>  at android.view.View.draw(View.java:6989)
> at android.widget.FrameLayout.draw(FrameLayout.java:361)
>  at 
> com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1882)
> at android.view.ViewRoot.draw(ViewRoot.java:1544)
>  at android.view.ViewRoot.performTraversals(ViewRoot.java:1280)
> at android.view.ViewRoot.handleMessage(ViewRoot.java:1882)
>  at android.os.Handler.dispatchMessage(Handler.java:99)
> at android.os.Looper.loop(Looper.java:130)
>  at android.app.ActivityThread.main(ActivityThread.java:3701)
> at java.lang.reflect.Method.invokeNative(Native Method)
>  at java.lang.reflect.Method.invoke(Method.java:507)
> at 
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
>  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
> at dalvik.system.NativeStart.main(Native Method)
>
> The stack seems to relate to my Activity B structure. My app loads puts 
> large images on screen, so I have a couple "recycle()" calls on the 
> fragments that take part of Activity B,  but they're all inside 
> "!bitmap.isRecycled()" conditions, and they're all around the first steps 
> on the activity and fragments life cycle. Anyway, there is no recycle() 
> call in my whole project that it's not followed by some assignation, either 
> with null or with some generated bitmap. 
>
> When I debugged the exception didn't fire there. It just appears to be 
> "nowhere", jumping outright from the last line on my "onPause()" on 
> Activity B to the runtime exception. 
>
> To add some debug chance, I've set a handler 
> with setDefaultUncaughtExceptionHandler to check what the behaviour would 
> be after the Exception is thrown, and what I see is:
>
> * In a Samsung device with a Mod Gingerbreas, first the option on the menu 
> on Activity B disappearing, then the Activity B dissapearing into to 
> background, a black screen and just a couple seconds later I get an ANR. 
> * In an unrooted Sony device , I've got to the Activity A screen looking 
> just as if everything is OK, but there is no responsiveness at all and soon 
> I got to the ANR too.
>
> I know my question it's really feeble, but I just can't see how to find 
> where the exception is throwing. Any clues? 
>
> Thanks!
>
> Marina
>
>
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to