0

I know that a process is an executing instance of an a program running in the foreground or background and that background processes run asynchronously(runs outside the main thread).

Would background music in your application be an example of a background process?(doesn't freeze up your UI in the main thread and it runs in its own thread)

Does process imply then that another program is running the music in the background?

Jerry YY Rain
  • 4,134
  • 7
  • 35
  • 52
committedandroider
  • 8,711
  • 14
  • 71
  • 126

2 Answers2

1

I don't think that you need another process for playing music - you just need another thread. I don't think that you want to play music while your app is not in the foreground. For example if your app is a game which only produces sounds when it is active.

Obviously this is not true if your app is a media player which still plays music while in the background letting user interact with it using notifications which let the user play/pause, skip a song or stop playback.

Please see a question like this one: How to put media controller button on notification bar?

Community
  • 1
  • 1
wojciii
  • 4,253
  • 1
  • 30
  • 39
  • so process is just the application as a whole? Could you play your music as a service as well - long running operation that does not interact with the user? – committedandroider Jul 11 '14 at 09:40
  • One app can consist of one or more processes - since you can create a service which can be a distinct process (AFAIK). You should read http://developer.android.com/guide/components/fundamentals.html one of these days for background info. Yes, you can play music from a service. – wojciii Jul 11 '14 at 09:45
1

Your android application consist of process, services, threads, message queues. It application developer choice when to use what. As good developer, you should always try to make you application user experience smooth without and any hang. Always perform heavy/time consuming activity with service or async threads, and avoid such activity on main thread as it cause UI hangs.

user2670032
  • 305
  • 5
  • 5
  • can you explain the difference between process and async threads? Say i launch angry birds. Would the game(application itself) be the process? Would the background music be running as a service or its own async thread? – committedandroider Jul 11 '14 at 18:47
  • both AsyncTask and thread can be treated as similar,but developer should know where to use what... Async Task should be used for task which can be accomplished withing few miliseconds, whereas threads can be used to more time consuming task e.q downloading/high CPU task. Yes, every application have minimum one process.For good user experience you should always avoid putting everything in main process/thread, make use of service, process and threads – user2670032 Jul 14 '14 at 08:22