java - Android 有关于后台播放音乐的问题
PHPz
PHPz 2017-04-17 17:36:33
0
3
455

最近在做一个音乐播发器,我把播放音乐这个功能写在一个服务里,再和播放的界面进行绑定,注意是BindService而不是StartService。当我播放界面finish()后并且按理说服务也自动销毁了,但是音乐仍在播放,我用的是MediaPlayer类播放的音乐,不知道为什么,求大神告知。

PHPz
PHPz

学习是最好的投资!

reply all(3)
PHPzhong

Did you call unBind before finish?

伊谢尔伦

BindService will not be destroyed as long as there is another activity bound to this service. It must wait until all activities are called unbound() before it can be destroyed.


Service life cycle diagram

A practical experience is to send a message to the Service before the activity's unBound() to tell the service that the activity is to be unbound. This blog post has some source code and an introduction to Android BoundService inter-process communication

In addition, does Mediaplayer call release() in onDestroy of service?

小葫芦

Only the current playback interface is bound to it, and the mediaplayer is not released in the service. But logically speaking, since my activity has been finished and the bound service has been destroyed, the mediaplayer in the service should also be destroyed.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template