0

*I am writing this code on button click .

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();
    }*

but service method onDestory is called.Service is not stop.Help me how to stop service in activity

Padma Kumar
  • 19,893
  • 17
  • 73
  • 130

2 Answers2

0

when you call

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

service will stop when he can

Once requested to stop with stopSelf() or stopService(), the system destroys the service as soon as possible. It is from http://developer.android.com/guide/components/services.html#Stopping

Roman Kazanovskyi
  • 3,370
  • 1
  • 21
  • 22
0

try this on button click ....

button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
               Intent intent=new Intent(DownloadQueueActivity.this, ProductDownloadService.class);
        stopService(intent);
             }
         });
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133