android - Event Raise on Service -


think have service play musics , have actvity bind service , want when service started new music , raise event , activity shows toast , how can , here

service service = new se... bindtoservice();  service.onmediaplayerstarted(new event(  public void run() {  }; )); 

i want craete custom event mediaplayerstarted , when

you can in 2 ways:

1) use localbroadcastmanager , write receiver sending , receiving broadcasts within application (might heavy , complex, not expanding details, works).

2) use message passing using handler (this simple).

  • create handler in main activity , pass reference service
  • send empty message using activity handler respective event id , update ui accordingly in activity.
  • refer example. - user timertask , runnables pupose send empty message using handler , handle them in handlemessage(message msg) call of handler.

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -