I am trying to programmatically raise the volume to the STREAM_MUSIC
stream's maximum value, but I am having a "Sending message to a Handler on a dead thread" issue when I do. Also, it seems like it does not raise the volume 100% of the time, although when I get this error, it will raise it MOST of the time.
The code is:
System.out.println("Maximum volume for this stream is: "+maxstreamvol+" and it used to be set to: "+currentvol);
final AudioManager am = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
am.setStreamVolume(AudioManager.STREAM_MUSIC, maxstreamvol, AudioManager.FLAG_SHOW_UI);
am.setStreamSolo(AudioManager.STREAM_MUSIC, true);
System.out.println("Volume Raised!");
After googling around, it seems that this error has to do with multi-threaded situations... The code at this point should be running on the UI thread.
In fact, I even surrounded it with:
runOnUiThread(new Runnable() {
public void run() {
// code_goes_here
}
});
And, that produced the same error. The error that I am seeing is this:
I/System.out(24949): Maximum volume for this stream is: 15 and it used to be set to: 0
W/MessageQueue( 490): Handler (android.media.AudioManager$FocusEventHandlerDelegate$1) {42b52f28} sending message to a Handler on a dead thread
W/MessageQueue( 490): java.lang.RuntimeException: Handler (android.media.AudioManager$FocusEventHandlerDelegate$1) {42b52f28} sending message to a Handler on a dead thread
W/MessageQueue( 490): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:294)
W/MessageQueue( 490): at android.os.Handler.enqueueMessage(Handler.java:618)
W/MessageQueue( 490): at android.os.Handler.sendMessageAtTime(Handler.java:587)
W/MessageQueue( 490): at android.os.Handler.sendMessageDelayed(Handler.java:558)
W/MessageQueue( 490): at android.os.Handler.sendMessage(Handler.java:495)
W/MessageQueue( 490): at android.media.AudioManager$1.dispatchAudioFocusChange(AudioManager.java:1894)
W/MessageQueue( 490): at android.media.IAudioFocusDispatcher$Stub.onTransact(IAudioFocusDispatcher.java:57)
W/MessageQueue( 490): at android.os.Binder.execTransact(Binder.java:351)
W/MessageQueue( 490): at dalvik.system.NativeStart.run(Native Method)
I/System.out(24949): Volume Raised!
Does anybody know what's happening here?