One Service Multiple Activities in Android -


i have service , 3 activities. service started in first activity. when move second activity , pressing on button, want send data service.

so in second activity, inside click listener did following:

 intent service = new intent(myservice.class.getname());   service.putextra("datatosend",data.tostring());  startservice(service); 

but method onstartcommand inside service, doesn't called..

also, want create service work multiple activities. mean each activity able send data service , data it.

hi need bind running service activity need access again. following code snippets can used reference

@override protected void onstart() {     super.onstart();     intent mintent = new intent(this, myservice.class);     bindservice(mintent, mconnection, bind_auto_create); };  serviceconnection mconnection = new serviceconnection() {      public void onservicedisconnected(componentname name) {         mbounded = false;         myservice= null;     }      public void onserviceconnected(componentname name, ibinder service) {         // toast.maketext(context, "service connected", 1000).show();          mbounded = true;         localbinder mlocalbinder = (localbinder) service;         myservice= mlocalbinder.getserverinstance();        //now able access method in service class      } }; 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -