我收到报告称,在某些(不是全部)HTC Desire HD(FRF91、2.2)和 HTC EVO 4G(PC36100|3.29.651.5、2.2)上,TextToSpeech.OnInitListener.onInit(int)
在同一个对象上被重复调用(在几秒钟内超过 1500 次)。我的任何其他用户(或其他 Desire HD 用户)AFAICT 都不会发生这种行为。
代码是:
TextToSpeech tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
private int mCallCount = 0; // trying to investigate potential infinite loops
@Override
public void onInit(int status) {
if ((mCallCount % 100) == 1) {
// report this
}
mCallCount++;
}
});
有人有什么想法吗?
编辑:我也尝试调用 shutdown()
方法(第一次检测到多个监听器调用)但这似乎没有帮助。
最佳答案
也许你应该用你自己的中介方法来解决它,例如:
private long lastCall = 0;
private long deepBreath = 5*1000; //5 seconds
private boolean hasRested;
TextToSpeech tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
long thisCall = Calendar.getInstance().getTimeInMillis();
intermediaryMethod(status, thisCall);
}
});
//new method
public void intermediaryMethod(int status, long thisCall) {
hasRested = (thisCall-lastCall)>=deepBreath;
if (hasRested) {
lastCall = thisCall;
//do something about 'status'
}
}
关于android - TextToSpeech.OnInitListener.onInit(int) 被连续调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4819330/