使用onClickListener停止Service内的服务

时间:2015-11-15 17:40:45

标签: android service

我有一个简单的服务。我的问题是 b'{\n "error": {\n "errors": [\n {\n "domain": "global",\n "reason": "required",\n "message": "Permission type field required",\n "locationType": "other",\n "location": "permission.type"\n }\n ],\n "code": 400,\n "message": "Permission type field required"\n }\n}\n' 不起作用。

这是我的代码:

stopSelf()

2 个答案:

答案 0 :(得分:2)

一旦服务完成执行,就必须通过调用stopSelf()方法来自行停止服务。但是,您也可以通过调用stopService()方法自行停止服务。

re.findall()

对于stopself():

它应该在自动时自动调用,就像服务要完成工作一样,它被称为下面的东西,它会在一段时间后使用这个方法。

stopService(new Intent(YourActivity.this, MyService.class));

有关更多信息,请查看适合您问题的链接: - How to stop service by itself?

答案 1 :(得分:0)

我试过这个,现在我可以杀了我的服务

@Override
    public void onDestroy(){

        windowManager.removeView(view);

        super.onDestroy();  
    }