Re: [android-developers] Re: RuntimeException: Canvas: trying to use a recycled bitmap

2013-03-19 Thread Marina Cuello
I did. I changed some stuff to avoid out of memory errors --just for debug
sake, can't be done in the working app-- and then commented the calls and
the exception is thrown anyway. It seems like something outside my code is
trying to recycle some bitmap.

Marina

On Mon, Mar 18, 2013 at 4:19 PM, bob b...@coolfone.comze.com wrote:

 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
 

Re: [android-developers] Re: RuntimeException: Canvas: trying to use a recycled bitmap

2013-03-19 Thread bob
 

Does this happen if you don't use that Sherlock stuff?


If you use it, you will probably have to do a lot of detective work to 
figure this out.



On Tuesday, March 19, 2013 11:48:29 AM UTC-5, Marina Cuello wrote:

 I did. I changed some stuff to avoid out of memory errors --just for debug 
 sake, can't be done in the working app-- and then commented the calls and 
 the exception is thrown anyway. It seems like something outside my code is 
 trying to recycle some bitmap.

 Marina

 On Mon, Mar 18, 2013 at 4:19 PM, bob b...@coolfone.comze.comjavascript:
  wrote:

 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 

Re: [android-developers] Re: RuntimeException: Canvas: trying to use a recycled bitmap

2013-03-19 Thread Marina Cuello
I checked once again. There were a couple of recycle() that I didn't find
the first time I searched --my Eclipse sometimes lacks of memory for this
kind of tasks, it seems. I searched for the call among my files with
another app, and find the culprit on the onPause() of one of de Fragments.
Thanks!

Marina

On Tue, Mar 19, 2013 at 1:48 PM, Marina Cuello marina.ear...@gmail.comwrote:

 I did. I changed some stuff to avoid out of memory errors --just for debug
 sake, can't be done in the working app-- and then commented the calls and
 the exception is thrown anyway. It seems like something outside my code is
 trying to recycle some bitmap.

 Marina


 On Mon, Mar 18, 2013 at 4:19 PM, bob b...@coolfone.comze.com wrote:

 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