2016-05-31 90 views
0

我在我的应用程序中使用服务,但我通过从中获取对象来运行它,因为我将活动上下文传递给它,所以我想知道如何从活动中停止此服务从活动中停止服务

我的服务

public class Tracker extends Service implements LocationListener 

我如何启动它

T1=new Tracker(MainActivity.this); 

我试图

​​

也是我的服务定义

public void Close() 
{ 
    this.stopSelf(); 
} 

,并把它称为从主

T1.Close(); 

但它仍在运行

回答

0

要启动服务,你可以这样做:

Intent intent = new Intent(this, Tracker.class); 
startService(intent); 
要停止它:
Intent intent = new Intent(this, Tracker.class); 
stopService(intent); 

希望它有帮助。