在 onDestroy 方法中,在尝试关闭对象/将其关闭/等之前确定对象是否实际初始化的正确方法是什么?
例如,哪个更好:
protected void onDestroy()
{
if(tts != null)
{
tts.shutdown();
}
if(dbWord != null)
{
dbWord.close();
}
super.onDestroy();
}
或这个:
protected void onDestroy()
{
if(tts instanceof null)
{
tts.shutdown();
}
if(dbWord instanceof TextToSpeech)
{
dbWord.close();
}
super.onDestroy();
}