I currently have a listview and when you click on an item it takes you to a new window and starts playing the song associated to that position. The problem is when I press the back button to return to the listview and I press the same item, the music starts playing again, over what is already playing. Is there anyway to fix this, so that when you click on the same item and that song is playing, it won’t replay the song? Thanks
I currently have a listview and when you click on an item it takes
Share
Have a look at this article about creating a service to play music. Looks like what you are trying to do.
The other thing you could do is add a function that stops the music when the activies onPause or onStop methods are called. Then the inactive music playing activies will get destroyed by the android OS in its own good time, and you wont have to worry about having multiple music files playing. The down side to this method is that you will only have music playing while the new window is visible. If you change windows, it will halt because the onPause or onStop method will be called. If you want the music to play in the background, I think you need to use the service technique.
To start the service, you can bind to it with an intent or use the startService method.
For example, in the article linked above, the service is started here:
The official Android Services api page should give you a good overview of how to deal with services.