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. Cant catch onItemClick when use checkBox in ListView

Search this group, this was discussed here very recently.






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

2. Cant catch onItemClick when use checkBox in ListView

Hi, guys! I want to use ListView each Item of wich has checkBox. I
want checkBox check and uncheck when I click it and some processes
runing when I click on item, but not on the checkBox. I'm trying to
use this layout as item:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:id="@+id/MainLayout"
        android:orientation="vertical"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:minHeight="57px">



                                        <CheckBox
                                                
android:layout_height="wrap_content"
                                                
android:layout_width="wrap_content"
                                                android:gravity="left"
                                                
android:layout_marginLeft="2px"/>


                                                <TextView 
android:id="@+id/NameOfGroup"
                                                        
android:layout_height="wrap_content"
                                                        
android:layout_width="fill_parent"
                                                        
android:textColor="#FFFFFF"
                                                        
android:singleLine="true"
                                                        android:minHeight="30px"
                                                        android:textSize="20px"
                                                        android:textStyle="bold"
                                                        
android:layout_marginLeft="5px"
                                                        
android:gravity="center_vertical|center_horizontal"/>
</RelativeLayout>


checkBox checks and unchecks as I want, but OnItemClickLictener
doesn't catch anything when I click on Item. However it makes what I
want if I choose and click it using trackball. What should I do?
--~--~---------~--~----~------------~-------~--~----~

3. Rotating the device / emulator?

4. where exactly the resize algorithm implementation inside surface flinger is performed for the use case of video playback

5. Contribute SuperH code to Android

6. What copybit does and where image conversion from YUV to RGB is implemented?

7. How the video display size making use of resize and rotation is set under Android