3

Recently my application received quite a lot comments that "it's not working" on Android Ice Cream Sandwich with CM9. I'm not able to reproduce the error on the emulator running Android 4.0 and thanks to the way android market works there's no way I can't contact those people to ask about the details.

Luckily, one crash error report caught my eye. I'm using Canvas.clipPath to draw rounded corners... and looks like some phones are throwing UnsupportedOperationException when trying to use that function. Quick look at Google reveals that it seems to be a problem when using hardware acceleration in Android 4.0 - so that's the potential reason of received comments.

The question is - what's going on? Weren't applications hardware accelerated in previous android versions? Why such common function isn't supported? What's the workaround?

Example usage of Canvas.clipPath can be found in my other post. Check the accepted answer here: Android rounded corners in ListView

Thanks in advance

Community
  • 1
  • 1
Sebastian Nowak
  • 5,607
  • 8
  • 67
  • 107
  • I found the same thing in my App. You can set android:hardwareAccelerated="false" in your Manifest.xml as a workaround. This worked in Honeycomb and presumably is valid in ICS – CjS Feb 16 '12 at 08:22

2 Answers2

6

In ICS, hardware acceleration was turned on by default. Until 4.0, the default was that hardware acceleration was off. Hardware acceleration does not support clipPath (and a few other operations, see more here http://android-developers.blogspot.com/2011/03/android-30-hardware-acceleration.html) I am facing the same issue. As a quick fix I will turn off acceleration for the entire application, and later I will rewrite the code not to use clipPath

yoah
  • 7,180
  • 2
  • 30
  • 30
  • Did you find away around ClipPath? – Oliver Dixon May 03 '12 at 12:36
  • @Olly Dixon No. I wanted to have hardware acceleration, so I ended up rewriting my code in a different way where clipPath is not used. – yoah May 04 '12 at 14:21
  • +1, Wow, Android never ceases to amaze me... No warning, exception, nothing, but half of your drawing code is simply turned into NOPs when you take a more recent SDK. – mvds Oct 18 '12 at 12:52
  • i am confused, if in ics hardware acceleration is turned on by default then why is clipPath failing? where can i see the list of canvas api which are safe with hardware acceleration? – numan salati Dec 19 '12 at 05:41
  • @numan Look at the link specified above (http://android-developers.blogspot.co.il/2011/03/android-30-hardware-acceleration.html). It has the full list of supported operations. – yoah Dec 20 '12 at 07:19
  • @yoah i've seen that. it for honeycomb release. i want to know for ics and jb. it should be in the api docs but unfortunately its not :( – numan salati Dec 20 '12 at 19:55
2

You can turn off hardware acceleration only on the specific view that is causing problems. Check out my answer here: https://stackoverflow.com/a/14054331/596708

Community
  • 1
  • 1
ffleandro
  • 4,039
  • 4
  • 33
  • 48