I would like to pass data from activity to service. Currently I am trying to use an ArrayList<HashMap<String, String>>
. What options do I have for passing this to the service? I was thinking about putting it as extra data in the intent but I'm not sure how to do this. Or is it possible to have this set up as some sort of global?
At the moment it is set up as a static of the activity, and the service is calling back to the activity to be provided with the next item from the ArrayList. I'm not happy with how that is working, so would like to move the list into the service.
EDIT
In response to the questions raised below:
I am trying to pass a playlist (yep, another media app) to the service. The playlist ArrayList<HashMap<String, String>>
contrains paired song info, such as "songTitle" , "this is a title".
I think however that i am getting confused with the lifecycle of the application. When a user clicks play, the service is created. If I used a static for the list, when the service is created it would see that list. So the service will happily continue to play songs from this list. However, if the user changes folder etc, how do I get the app to recognise the change in playlist? The way the app is designed, the user can untick tracks in the list at any time, or can browse to a different folder. When the song completes the new list should be loaded. What is the best way of doing that? Or is the way that I am doing it now the best way? When the song completes send a broadcast back to the main activity requesting the next track. Should I destroy the service at this point and allow the "next song" function recreate it?
Lifecycle confusion!