如何在应用程序被杀死并再次启动后停止Android START.STICKY服务

时间:2015-10-14 11:48:24

标签: android service background-service

我有使用FusedAPI进行收听位置更新的后台服务。

public class ListenLocation extends Service
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
            return Service.START_STICKY;
    } ... //code continues for location listener

我使用

从片段内部启动此服务
getActivity().startService(new Intent(getActivity(),ListenLocation.class));

这一切都运行正常,我在后台获取位置更新。

但是,一旦用户关闭了应用程序,如何停止此服务?

我尝试了以下但是它没有停止服务

getActivity().stopService(new Intent(getActivity(),ListenLocation.class));

停止此类服务的方法是什么?

0 个答案:

没有答案
相关问题