I am trying to create simple Android application to play audio files from sd card.
I have some problems with understanding Services.
I will be concrete, here are my questions.
- Service by default runs on UI thread, isn't it ? Only if it runs in separate process it has another thread, as well as context, because it is another process in system (fork of virtual machine instance)
- Where should be
MediaPlayer
class used ? In background service or in UI thread. As far as bound services run on UI thread, there is no sense in creating service bound and so on if it runs on UI thread ? Only in case we want to continue playing music in background while activity (or any UI component was destroyed) but in this case MusicPlayer will occupy whole UI thread even without UI visible to user. Am I right ? - I have found tons of tutorials how to create simple audio player, few of them shows how to run in separate thread directly from service, others just directly in service from activity using
IBinder
class which just returns instance of Service.
Please explain this topic. I would be grateful for any help. Thanks.