如何从片段开始服务 [英] how to start service from fragments
本文介绍了如何从片段开始服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从列表视图项的片段中启动服务.我正在尝试通过以下方式致电服务:
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?
推荐答案
替换
startService(new Intent(getActivity(),myPlayService.class));
使用
getActivity().startService(new Intent(getActivity(),myPlayService.class));
这篇关于如何从片段开始服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文