I am working on a live wallpaper that uses a AudioRecord object to listen to the phone's mic. This works fine until I start using the wallpaper and then also view the preview wallpaper in the wallpaper selection menu. When this happens, I start having problems starting and stopping the AudioRecord object. Currently this is handled by onVisibilityChanged:
@Override
public void onVisibilityChanged(boolean visible) {
if (this.visible == visible)
return;
this.visible = visible;
if (visible) {
recorder.startRecording();
handler.post(drawRunner);
} else {
recorder.stop();
handler.removeCallbacks(drawRunner);
}
}
Is there some solution to this? I have tried several things, but nothing has worked out. This solution does (rarely) work, and as far as I can tell this is because the two instances of the wallpaper engine update their visibility in an unpredictable order. Sometimes the main wallpaper sets itself to not be visible before the preview sets itself to be visible, and everything is fine. Sometimes this order is reversed and everything breaks.