service - ServieConnection Not Working At All Android -
good day.i have simplest scenario ever be!i have simple service connection taken google in app purchases example , own code
public class mainactivity extends activity { iinappbillingservice mservice; serviceconnection mserviceconn; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mserviceconn = new serviceconnection() { @override public void onservicedisconnected(componentname name) { mservice = null; toast.maketext(mainactivity.this,"disconnected",toast.length_long).show(); } @override public void onserviceconnected(componentname name, ibinder service) { mservice = iinappbillingservice.stub.asinterface(service); toast.maketext(mainactivity.this,"connected",toast.length_long).show(); } }; } @override public void ondestroy() { super.ondestroy(); if (mservice != null) { unbindservice(mserviceconn); } }
} first run worked , toasted.but afterwards never connect never trigger onserviceconnected , onservicedisconnected.doing researches in google did not found solution questions of familiar without responsible answers.thank beforehand , please tell me heck do?
you did not call bind service:
create intent , call bindservice
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mserviceconn = new serviceconnection() { @override public void onservicedisconnected(componentname name) { mservice = null; toast.maketext(mainactivity.this,"disconnected",toast.length_long).show(); } @override public void onserviceconnected(componentname name, ibinder service) { mservice = iinappbillingservice.stub.asinterface(service); toast.maketext(mainactivity.this,"connected",toast.length_long).show(); } }; intentfilter filter1 = new intentfilter("intentfiltername"); bindservice(filter1, mconnection, context.bind_auto_create); }
Comments
Post a Comment