开发者

Closing WordDBAdapter in onDestroy

开发者 https://www.devze.com 2023-03-21 10:58 出处:网络
I need to close my WordDBAdapter object in the onDestroy method in Android. Is one of these better than the other?

I need to close my WordDBAdapter object in the onDestroy method in Android. Is one of these better than the other?

@Override
protected void onDestroy()
{
    super.onDestroy();

    if(dbWord instanceof WordDBAdapter)
    {
        dbWord.close();
    }
}

----- OR ------

@Override
protected void on开发者_如何学编程Destroy()
{
    super.onDestroy();

    if(dbWord != null)
    {
        dbWord.close();
    }
}

Thanks!


There is a problem in your code, whatever approach you use the ordering of statement should be as follow:

@Override
protected void onDestroy()
{
    if(dbWord != null)
    {
        dbWord.close();
    }
 super.onDestroy();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消