*我在点击按钮时编写此代码。
public void onstopServiceClickHandler(View view){
Intent intent=new Intent(DownloadQueueActivity.this, ProductDownloadService.class);
stopService(intent);
//lv_productList.setAdapter(downloadQueueAdapter);
//startServiceButton.setVisibility(View.VISIBLE);
Toast.makeText(_instance, "click stop service",Toast.LENGTH_SHORT).show();
}*
但调用服务方法onDestory.Service不会停止。帮助我如何在活动中停止服务
答案 0 :(得分:0)
点击按钮后尝试此操作....
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent(DownloadQueueActivity.this, ProductDownloadService.class);
stopService(intent);
}
});
答案 1 :(得分:0)
致电
stopService(new Intent(this, MyService.class));
服务将在他可以
时停止一旦请求使用stopSelf()或stopService()停止,系统会尽快销毁服务。来自http://developer.android.com/guide/components/services.html#Stopping