dongs
dongs
  • 发布:2016-06-24 16:58
  • 更新:2019-05-06 15:51
  • 阅读:1867

[已解决]使用pWebview.getContext().startService(intent);开启一个服务后怎么停止?

分类:5+ SDK

安卓启动服务代码

Intent intent = null;  
public String GeolocationFullStart(IWebview pWebview, JSONArray array) {  
        // 获取参数 可以是多个  
        String inValue1 = array.optString(0);  
        Log.i("GeolocationFull", "GeolocationFullStart");  
        // 创建服务类型  
        intent = new Intent(pWebview.getContext(),GeolocationFullService.class);   
        // 开启服务  
        pWebview.getContext().startService(intent);  

        String ReturnValue = inValue1;  
        // 只能返回String类型到JS层。  
        return JSUtil.wrapJsVar(ReturnValue, true);  
    }

安卓关闭服务代码如下

    public String GeolocationFullStop(IWebview pWebview, JSONArray array) {  
        // 获取参数 可以是多个  
        String inValue1 = array.optString(0);  
        Log.i("GeolocationFull", "GeolocationFullStop");  
        intent = new Intent(pWebview.getContext(),GeolocationFullService.class);   
        // 关闭服务  
        pWebview.getContext().stopService(intent);  
        String ReturnValue = inValue1;  
        // 只能返回String类型到JS层。  
        return JSUtil.wrapJsVar(ReturnValue, true);  
    }

PS:本人不会安卓开发,都视依葫芦画瓢。
另外:给各位提醒一下,服务里创建的计时器,在停止服务的时候计时器不会自动停止,必须手动停止。

2016-06-24 16:58 2 条评论 负责人:无 分享
已邀请:
4***@qq.com

4***@qq.com

@dongs 请问你这是做后台服务 实时定位吗?

l***@live.com

该问题目前已经被锁定, 无法添加新回复