开发者

Android- Destroy media player service when click on item in Listview

开发者 https://www.devze.com 2023-03-20 19:55 出处:网络
I currently have a listview and when you click on an item it runs a service with a mediaplayer. If I click on another item in the listview the service that\'s running should stop and run the new servi

I currently have a listview and when you click on an item it runs a service with a mediaplayer. If I click on another item in the listview the service that's running should stop and run the new service. What would be the best way of handling this? Would it be to use the onDestroy开发者_如何学Go? Thanks a lot.


If you ask me you should not stop and restart service like this but i don't know the exact situation as may be its the necessity of your app.

You should call context.stopService(yourServiceIntent) in your ListView's onItemClick() then restart the service with new input using putExtra() in the same onItemClick().

But i still recommend you to find an alternative to this service stop and restart procedure as it could affect the performance of your app by decreasing the response time.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号