0
在onDestroy方法中,什麼是正確的方式來確定一個對象在嘗試關閉/關閉/ etc之前是否被實際初始化了。關閉和關閉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();
}