Exception locking surface - lockCanvas() returns a null?

by Dianne Hackborn » Fri, 10 Apr 2009 06:31:04 GMT


Sponsored Links
 If you want to use the standard 2d APIs, don't use OpenGL.







-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~



Exception locking surface - lockCanvas() returns a null?

by Stoyan Damov » Sat, 11 Apr 2009 02:28:52 GMT


 Just my 2 stotinki -- I see more and more developers using this WRONG
resource acquisition pattern with try...finally:

try
{
    acquireResource();
}
finally
{
    releaseResource();
}

This is plain wrong. The correct way to obtain a resource and release
it is to acquire it BEFORE the try block, and release it in the
finally block:

acquireResource();
try
{
    // do whatever with the resource
}
finally
{
    releaseResource();
}

if acquireResource could throw an error, the correct way to handle it
is in an outer try block:

try
{
    acquireResource();
    try
    {
        // do whatever with the resource
    }
    finally
    {
        releaseResource();
    }
}
catch (WhateverException e)
{
}

as opposed to this anti-pattern (again widely used):

Resource r = null;
try
{
    r = acquireResource();
    // do whatever with the resource
}
finally
{
    if (r != null)
    {
        releaseResource();
    }
}

Cheers







--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. even i have an color state issue with list view selection & swipe

Requirement :

on touch / pressed
d-pad scroll
: list elements should highlight should be white & list background
should be magenta color

during swipe left / right , up / down
the list view should not get highlighted

but i am facing problem ... list background is becoming white
( default ) but the highlight of list elements ( white ) - so i am
seeing like white ...

can any one help me to solve this issue ....


list selector

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_focused="true"
        android:drawable="@drawable/magenta_bg" />
    <item
        android:state_pressed="true"

        android:drawable="@drawable/magenta_bg" />
         <item
        android:state_selected="true"
        android:drawable="@drawable/magenta_bg" />
</selector>

List Text element color

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:state_selected="true"
    android:color="@color/white" />
<item
    android:state_pressed="true"
    android:color="@color/white" />
<item
    android:color="@color/black" />
</selector>




-- 

2. Design/"flowchart" scheme for Android apps?

I'm seeing that it would be good to have some sort of charting scheme
(or possibly just a table-based design strategy) when designing
Android apps.  Have any such schemes been proposed?

-- 

3. OpenGL version info

4. Want to render external buffers on the surface created at JAVA level.

5. Can I create a file in /data in android?

6. ANDROID_ELASPED_REALTIME_WAKEUP

7. Android Image From FFMPEG AVPicture