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. In App Billing enhancement request

Would it be possible to allow the in-app billing to check the purchase
status of an app? I want to switch a paid app to a freemium model, but
it's not possible to switch and allow existing paid users to keep
access to the app.

This could easily be remedied with a new reserved product id,
something like 'android.app_purchase' that could be retrieved by the
billing API. It would be present for any users that have purchased the
app. It would, of course, need to be present even if the app is
switched to a free app for those users that previously purchased when
it was paid.

If someone has an alternate mechanism to switch a paid app to freemium
and keep access for existing users, please let me know!

Thanks

-Marcus Watkins
Versatile Monkey

-- 

2. random 404 on google android pages

Hi

I've been trying to upload a new version of my apps for the past 7
hours without much luck.
http://market.android.com/publish returns 404 or times out constantly.

Any news on what's going on? I entered IRC and checked twitter and it
seems a widespread problem for the past 20 hours, but I see no news or
posts in here.

Regards,
Joaquin Grech

-- 

3. ListPreference.getSummary

4. Widget RemoteViews and autoLink

5. Combine multiple audio files and encode it to .mp3

6. GridView over scroll problem

7. parsing of silver light response