In my Android application I use TTS and Voice Recognition. Despite using all the available callbacks to understand the status they are in, I still get situations that I cannot handle. Examples:
1) TTS reports successful initialisation, but fails to speak (known issue for some custom TTS engines (mentioning no names)).
2) Network access is lost after initial successful connection, which can result in a huge amount of lag before a network error is returned.
There are other situations that I won't bore you with.
I've read and digested time monitoring threads such as this and this so I understand how to accurately determine the time between X&Y, but it's a monitoring method that I'm after, which I can react to when a set limit is reached.
Excuse my pseudo-code, but I hold my hands up, I've no idea where to begin on this..
public boolean methodSuccess = false;
public void troublesomeMethod() {
if(// everything completed and I got a usual result) {
methodSuccess = true;
}
public boolean timeMonitor(int maxDuration) {
// use System.currentTimeMillis() here as start value
// monitor time elapsed here in loop
// monitor methodSuccess in loop
// return false if methodSuccess is set to true whilst in loop
// break if maxDuration reached and return true
}
Again, excuse the above code, I simply can't think how to achieve this...
In addition, if I started the above with:
boolean monitorThis = timeMonitor(5000); // let me know when 5 seconds have passed
startTroublesomeMethod(); // the one I want to monitor
Then it would be pointless if I had to 'wait' on the boolean response being returned before startTroublesomeMethod() actually began! Or the troublesomeMethod began before I started monitoring it...
if(monitorThis) {
// react to lagging method by destroying TTS or Listener Object
} else {
// the troublesomeMethod behaved normally - do nothing
}
I hope in my confusion I've managed to express what I'm trying to achieve.
I thank you in advance for your help.