how to start service from fragments

拥有回忆 提交于 2019-12-03 04:14:29

问题


I want to start service from fragment from a list view item. I am trying to call service with:

startService(new Intent(getActivity(),myPlayService.class));

But it wont work at all. How do i call my service from fragments? Is there any another way to start service?


回答1:


Replace

startService(new Intent(getActivity(),myPlayService.class));

with

getActivity().startService(new Intent(getActivity(),myPlayService.class));



来源:https://stackoverflow.com/questions/13007355/how-to-start-service-from-fragments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!