android bound service with scala - cant get Binder.getService working -
i trying android app developed in scala work. error during compile
[error] testservice.scala:49: error: type mismatch; [info] found : .services.testservice.type (with underlying type object .services.testservice) [info] required: .services.testservice
service
class testservice extends service { val mbinder: ibinder = new testservice.testservicebinder val list = list("linux", "android", "ios", "wp") override def oncreate { toast.maketext(this, tag + " created", toast.length_long).show; log.d(tag, "oncreate"); } override def ondestroy { toast.maketext(this, tag + " destroyed", toast.length_long).show; log.d(tag, "oncreate"); } override def onstart(intent: intent, startid: int) { toast.maketext(this, tag + " started", toast.length_long).show; log.d(tag, "onstart"); } override def onbind(intent: intent): ibinder = mbinder def getlist: list[string] = list } object testservice { class testservicebinder extends binder { def getservice: testservice = testservice.this } }
activity
class homeactivity extends activity findview { private final val tag = "homeactivity" lazy val buttontest: button = findview[button](r.id.testbutton) private var mservice: testservice = _ private var mbound: boolean = false val mconnection: serviceconnection = new testserviceconnection override def oncreate(savedinstancestate: bundle) { super.oncreate(savedinstancestate) setcontentview(r.layout.main) buttontest.setonclicklistener(buttontestonclicklistener) log.i(tag, "oncreate") } override def onstart { super.onstart val intent: intent = new intent(this, classof[testservice]) bindservice(intent, mconnection, context.bind_auto_create); } override def onstop { super.onstop if(mbound) { unbindservice(mconnection) mbound = false } } object buttontestonclicklistener extends view.onclicklistener { def onclick(v: view) { if(mbound) { toast.maketext(v.getcontext, mservice.getlist.tostring, toast.length_long).show } } } class testserviceconnection extends serviceconnection { def onserviceconnected(classname: componentname, service: ibinder) { val binder = (new testservice.testservicebinder).asinstanceof[testservicebinder] mservice = binder.getservice mbound = true } def onservicedisconnected(classname: componentname) { mbound = false } } }
i hope can me or give me tutorial how bound services in scala work. assistance. chris
edit line 49 is: def getservice: testservice = testservice.this
i'm not sure understand why getservice looks looks. why not way:
def getservice: testservice = new testservice
the second thing not understand following line
val binder = (new testservice.testservicebinder).asinstanceof[testservicebinder]
why need asinstanceof here?
edit think have in android documentation. in companion object (like have implemented it) can not access this.
class localservice extends service { private final val localbinder = new localbinder() class localbinder extends binder { def getservice: localservice = localservice.this } }
Comments
Post a Comment