简体   繁体   中英

If I implement Android MediaPlayer in Activity instead of Service, what'll be the problems?

I've already implemented an Android music player just in an activity instead of Service. MediaPlayer class runs in background ( onPause() ) for a long time and I noticed it doesn't stop until I destroy the app instance. So why do I need Service for media player? Is it really necessary?

You need it for when your application is running. Your activities run on the main thread (AKA the UI thread). Performing a task in the UI thread for longer than 5 seconds produces an ANR (Application is Not Responding) dialog alert. This is because you are preventing the user from interacting with your app, thus making it unresponsive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM