1

I'm beginner in Android development. I try to create kind of MusicPlayer, which uses Service for playing music. When I click buttons in MainActivity, I call startService with Intent, which includes signal for action, such as play, pause, stop, etc... But I want to send data back from service to activity. For example, when current track has stopped and begin to play the next one, MainActivity got to receive track name and author name. Or when last track in the playlist is stopped, button "Pause" on the Activity got to changed to "Play". I need to send data as map. Like "title: value", "playing: false". So, what I tried. At first PendingIntent. I create it in the Activity and send by startService to the Service. I need to specify request code in PendingIntent, sting action in Intent for this PendingIntent. I don't know, how to use it. Then I tried bindService. But Service send data only if Activity request it. Another examples I didn't find.

Which way is most simple to send data from Service to Activity?

4

1 回答 1

1

使用信使从 onHandleIntent() 方法上的服务发送消息,然后使用处理程序接收它...请参阅本教程http://www.vogella.com/articles/AndroidServices/article.html

于 2013-07-28T15:21:57.387 回答