android - How to stop service immediately and forever -


can please explain me why service doesn't stop? , how stop service when device locked , stop forever. activity:

public class mainactivity extends activity {     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         startservice(new intent(this, myservice.class));         intentfilter filter = new intentfilter(intent.action_screen_off);         filter.addaction(intent.action_screen_on);         broadcastreceiver mreceiver = new myreceiver();         registerreceiver(mreceiver, filter);     } } 

my receiver:

public class myreceiver extends broadcastreceiver {     @override     public void onreceive(context context, intent intent) {         string action = intent.getaction();         if(intent.action_screen_on.equals(action)) {             log.i("isscreen ","on");         } else         if(intent.action_screen_off.equals(action)) {             log.i("isscreen ","off");             context.stopservice(new intent(context, myservice.class));         }     } } 

my service:

public class myservice extends service {     @override     public ibinder onbind(intent intent) {         return null;     }      @override     public void oncreate() {         super.oncreate();         log.i("service ","starts");     } } 

do try 1 ?

boolean isbound = false; ... isbound = getapplicationcontext().bindservice( new intent(getapplicationcontext(), serviceui.class), serviceconnection, context.bind_auto_create ); ... if (isbound)     getapplicationcontext().unbindservice(serviceconnection); 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -