How to call stopservice() method of Service class from the calling activity class
<p>I am trying to call my service class's stopService() method from my activity.
But I dont know how to access stopservice method from my activity class.
I have the below code but its not working...........</p>

<blockquote>
  <p>This is HomeScreen class:</p>
</blockquote>

<pre><code> public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        enablecheck = (CheckBox)findViewById(R.id.enablecheck);            

        enablecheck.setOnCheckedChangeListener(new OnCheckedChangeListener()
        {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                if(enablecheck.isChecked()){    
                    startService(new Intent(HomeScreen.this, AutoService.class));
                }else
                {
                    stopService(new Intent(HomeScreen.this, AutoService.class));

                }                       
            }

        });

    }
</code></pre>

<blockquote>
<pre><code>This is Service Class:
</code></pre>
</blockquote>

<pre><code>public class AutoService extends Service {

    private static final String TAG = "AutoService";
    private Timer timer;    
    private TimerTask task;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        Toast.makeText(this, "Auto Service Created", Toast.LENGTH_LONG).show();
        Log.d(TAG, "onCreate");     

        int delay = 5000; // delay for 5 sec.
        int period = 5000; // repeat every sec.

        timer = new Timer();

        timer.scheduleAtFixedRate(task = new TimerTask(){
            public void run() 
            {
                System.out.println("done");
            }   
        }, delay, period);


    }


    @Override
    public boolean stopService(Intent name) {
        // TODO Auto-generated method stub
        timer.cancel();
        task.cancel();
        return super.stopService(name);

    }


}
</code></pre>

<p>Any suggestion highly appreciable.
Thanks and Regards
Mintu</p>
