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? Thanks a lot.
I currently have a listview and when you click on an item it runs
Share
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’sonItemClick()then restart the service with new input usingputExtra()in the sameonItemClick().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.