1

I am doing some tests about Service and I find that when I do a heavy task in Service, it will block the UI thread, but when I start MediaPlayer in Service it does not block the UI thread.

I do not know why it is not blocking the UI thread. Is it run in a background thread or something else?

Albert Khang
  • 621
  • 6
  • 17

1 Answers1

0

Normally MediaPlayer does not run in the background. Please note that Service itself runs in the main thread. The Service can be used in tasks with no UI, but shouldn't be too long. If you need to perform long tasks, you must use threads within Service or use IntentService.

Amirhosein
  • 4,266
  • 4
  • 22
  • 35
  • "Normally MediaPlayer does not run in the background" - You mean it runs in the background thread, right? And where do you read about this? I searched for this but don't see anything useful? – Albert Khang Dec 28 '20 at 12:15
  • 1
    You can create and use MediaPlayer from background thread. But to receive callbacks on the background thread that thread must have Looper implemented. If thread does not have Looper callbacks will be called on the main (UI) thread. – Amirhosein Dec 28 '20 at 12:46