2011-06-28 17 views
0

我想结束我的类stopService();,我用这个方法,但我知道那是假的,请大家帮帮我:如何关闭主类stopService

if (Main_Page.this.finish() == true){ 
stopService(svc); 
} 

谢谢...

回答

1

使用本

public void onDestroy(){ 
super.onDestroy(); 
stopService(new Intent(this,yourservice.class)); 
} 
+1

谢谢,这是工作。 –

1

如果你要停止你的服务..然后做在的onDestroy()调用回你的活动

public void onDestroy(){ 
super.onDestroy(); 
stopService(svc); 
} 
+1

谢谢,但是当我用onDestroy svc无法解析变量时。 –

+0

你应该使用stopService(this,yourservice.class); – Sujit

+0

yup ..你应该使用stopService(this,yourservice.class),但记住一个服务只能停止,如果停止服务与你开始它相同的上下文。 –