Android problems binding started service -


i start service in oncreate() (if oncreate called first time) , call bindservice in onstart(). service probaply works, after calling bindservice local instance of service still null. furthermore, seems getservice() not called.? here code:

@override protected void oncreate(bundle savedinstancestate) { ... if(savedinstancestate == null){    final intent = new intent(this, hostservice.class);    startservice(i); }  }  protected void onstart(){     super.onstart();     bindservice(new intent(this, startgameactivity.class), connection, context.bind_auto_create); }  private serviceconnection connection = new serviceconnection(){      @override     public void onserviceconnected(componentname arg0, ibinder arg1) {         hostbinder binder = (hostbinder) arg1;         hostservice = binder.getservice();         isbound = true;     }      @override     public void onservicedisconnected(componentname arg0) {         isbound = false;     }  }; 

and in hostservice:

... private hostbinder binder = new hostbinder(); ... public class hostbinder extends binder{     hostservice getservice(){         log.d(tag, "getservice");         return hostservice.this;     } }  @override public ibinder onbind(intent arg0) {     return binder; } 

why hostservice still null, after onstart() called , why getservice not getting called ("getservice" not print in logcat)?

thx & regards

you don't need call startservice(); started bindservice().

in onstart() method, you're creating intent launch startgameactivity.class. wanted, or did mean launch hostservice.class?

if neither of problem, need more go on. can put logging statement inside onserviceconnected() , onbind() methods can sure they're called?

any logcat messages interesting?

are talking service via binder, or via messaging?


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -