I'm working with some code that calls the AudioRecord constructor:
AudioRecord listener = new AudioRecord(list of parameters);
do {} while (listener.getState() != AudioRecord.STATE_INITIALIZED);
This code would seem to make sense if AudioRecord goes off in another thread and takes time to initialize. I'm not sure of this is the case though, and if it isn't it would seem a lot better to have the code just check and return an exception, lest an infinite loop is started at some point when initialization does actually fail (although I could just limit the number of checks to something finite).
Should I leave the code as it is or replace the second line with something like the following?
if(listener.getState() != AudioRecord.STATE_INITIALIZED) {
throw new Exception("AudioRecord failed to initialize");
}