Closing WordDBAdapter in onDestroy
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();
}
精彩评论