Nevermind, I just realized (had pointed out) that I was using
dispatchMessage instead of handleMessage.

Thanks anyway!

vol wrote:
> Some quick background: In an effort to teach myself Services, IPC, and
> the general interplay, I have been creating a Music Player program.
> There is a Music Player Activity, and a Music Player Service. The
> Activity binds to the Service, and in the onServiceConnected method
> starts the Service. The Service then creates a MediaPlayer and loads a
> resource to play. This loading is done in a seperate thread. Upon
> completion of loading the resource, a message is sent via IPC from the
> Service to the Activity (this works) stating that the resource is
> loaded. The method that handles this immediately sends back a play
> command via IPC (this works). Upon recieving this play command, the
> Service starts playing the MediaPlayer and sends a playing message to
> the activity via IPC (this works!)
>
> Now, the trouble comes in here. The Activity contains a start, pause,
> and stop button. The pause button is disabled in the activity's
> creation. When the playing message comes in, I want to enable the
> pause button. The problem is, at this point, I have no idea what to do
> because nothing is working as it should.
>
> If I just call onPause.setEnabled(true), an exception is silently
> captured, and the button is active (albiet still grayed out).
>
> So, I tried to create an anonymous inner Handler object in the
> Activity, overriding the dispatchMessage, and have that call
> setEnabled(true) for certain messages. This works if I try calling it
> explicitly within the Activity, such as in the onCreate or onStart
> methods. However, if the "playing" method creates a message for this
> Handler and dispatches it, the Handler runs in the same thread that's
> handling the "playing" method, which is the wrong thread! This means
> that two seperate threads have been able to run this Handler's
> dispatchMessage method, which from what I understand of the
> documentation is distinctly not supposed to happen!
>
> Is this a known issue? Is it something I can work around? Am I simply
> doing this wrong? What is going on here?
>
> General Layout:
>
> Activity {
>   Button onPause
>   onCreate {
>     mHandler.dispatchMessage(IGNORE_THIS);
>   }
>   ....
>   ServiceCallback callback {
>     ....
>     "playing" method { mHandler.dispatchMessage(ENABLE_PAUSE); }
>     ....
>   }
>   ....
>   Handler mHandler {
>     handleMessage {
>       if(msg.what == IGNORE_THIS) return;
>       if(msg.what == ENABLE_PAUSE) onPause.setEnabled(true);
>     }
>   }
> }
>
> Service {
>
>   MediaPlayer player
>   RemoteCallbackList mCallbacks
>   ...
>   Handler mHandler {
>     mCallbacks.beginBroadcast()
>     mCallbacks.getBroadcastItem(i).playing()
>     mCallbacks.finishBroadcast()
>   }
>   ...
>   play { player.start(); mHandler.dispatchMessage(playing message); }
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to