Well... Here is the background:
I'm working in a experimental app that uses pocketsphinx. Basically, I'm running one service that runs a thread. This thread manages a RecognizerTask object. It gives a signal to the RecognizerTask object to start recording and recognizing the speech and after 15 seconds, it signals shutdown to the RecognizerTask object. Right after, it signals start again and the procedure repeats.
Follows the code of the thread that manages the RecognizerTask object:
public void run() {
while(!this.interrupted){
try{
Thread.sleep(15000);
}
catch (InterruptedException e){
e.printStackTrace();
return;
}
rec.shutdown();
try {
rec_thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
if(Thread.interrupted())
return;
rec = new RecognizerTask();
rec_thread = new Thread(rec);
System.gc();
rec.setRecognitionListener(MyService.this);
rec_thread.start();
rec.start();
}
}
The problem in here is the following: If the device is awake and the screen, turned on, everything runs fine. But if the screen is locked, the thread just freezes at the .join() call. Inspecting further, I realized that the .join() freezes because one call to the AudioRecord instance that exists inside the ReconizerTask object just does not return! And as soon as I unlock the phone, everything runs fine again! Also, my service acquire a Partial Awake Lock, while it's running.
And worse: this only happens with Galaxy S3 devices (the virtual devices and a Galaxy Nexus didn't show this behavior), as far as I know.
So, the question is: what can be causing this problem?