如下面的代码所示,当我在构造函数中实例化一个对象时,run方法正常工作,但是如果我在run方法中实例化了该对象,则我没有收到任何结果。
为什么会这样?
码:
private class TTSReg extends TimerTask {
TTSCtrl mTTS = null;
TTSReg() {
this.mTTS = new TTSCtrl(getApplicationContext());
}
@Override
public void run() {
//this.mTTS = new TTSCtrl(getApplicationContext());//if this line was activated, the rest would not work
if ((mVelocity < 1) && (mEngSpeed >= 600)) {
this.mTTS.pronounce(getApplicationContext().getResources().getString(R.string.rule_velocity_1));
}
}
}