Communication between Class and Main Activity Android -


i new in android hope can excuse ignorance

i made activity control bluetooth devices telephone, working generate new class activity, class take care of bluetooth communication.

i have questions:

first: in activty employed 1 broadcast receiver listen actions of bluetooth adapter state_on, bond_bonded... using actions update views, call methods , on.

so, possible keep listening broadcast receiver inside class , send changes main activity update views , on?

second: need send information bluetooth class main activity, information read devices, information broadcast receiver... so, best way pass information between class , main activity?

well, lot :)

the onreceive() method of broadcastreceiver called main thread: "this method called within main thread of process" (http://developer.android.com/reference/android/content/broadcastreceiver.html#onreceive(android.content.context, android.content.intent)).

that means can update ui onreceive() method. need use local class so:

broadcastreceiver mbroadcastreceiver = new broadcastreceiver() {     @override     public void onreceive(context context, intent intent) {         // update ui     } }; 

register receiver programmatically (instead of defining in manifest) , you're go:

context.registerreceiver(android.content.broadcastreceiver, android.content.intentfilter) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -