简体   繁体   中英

Music Player in Notification Bar Architecture

So I'm creating an app with MVVM, which is a Music Player, managed by Notification Bar. The only action I want to use Activity for is to start the player.

Right now all the logic is in the activity, and the app works perfectly fine this way. But I want to move the logic someplace else. When I relocate all the logic to a regular class, though, I can't access the Viewmodel. What would be the right way to separate player instantiation from its management? Fragment? Service? Something else?

Thanks in advance. Any ideas will be very appreciated.

notification bar

In the end it turns out that the best way to manage player and its inner state in a started bound service. It should be started so it won't stop when an activity goes down, and it should be bound in case you want to connect notification to activity.

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