android-how to stop services in android -


i want stop service when come activity . activity code :

stopservice(new intent(this, services_chat.class)); 

on call on mainactivity , in oncreate method . called .

this service code:

public class services_chat extends service {      @override     public ibinder onbind(intent intent) {         // todo auto-generated method stub         return null;     }      @override     public int onstartcommand(intent intent, int flags, int startid) {         new timer().scheduleatfixedrate(new timertask() {             @override             public void run() {                 log.v("this","caa");              }         }, 0, 1000);//put here time 1000 milliseconds=1 second         return start_not_sticky;     }      @override     public void ondestroy() {         super.ondestroy();     } } 

as can seen log , run code every second , after running app , calls stopping service , doesn't stop , still runs .

how can stop service ?

thanks

write method in services_chat class.

@override public boolean stopservice(intent name) {     // todo auto-generated method stub     timer.cancel();     task.cancel();     return super.stopservice(name); } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -