Android SDK 2.0.1.19 - RFIDHandler - ViewPager,Fragments

// Expert user has replied.
H Haresh Seetharaman 3 years 7 months ago
38 1 0

Hello All ,
I've looked up at the SDK Sample applications , provided by Zebra and i must say they have a seamless integration into Activities by passing the Context of the activity from which they're being called from.
Now let's say that i have an activity and multiple fragments attached to the Activity , and each of these fragments needs to leverage the RFID Methods , in order to scan the Tags . (for ex - fragment 1, 2, 3,4 ,5 Fragments out of which 2nd Fragment and 4th Fragment don't require the RFID Handler to be initialised and 1,3,5 Fragments require them to be initialized.)
val rfidHandler : RFIDHandler ? = RFIDHandler()
Now the question here is :
1. Can i initialise the RFIDHandler at each Fragment's OnCreate Method ?
2. How do i use the SDK Sample Application with a view Pager with multiple Fragments and one activity and setting RFID to true or false only when required .
3. How do i disable Barcode Scanning, when not required in an activity / Fragment .
Please refer to the Link for SDK Sample.
https://www.zebra.com/us/en/support-downloads/software/developer-tools/r...
Please Download the application which incorporate the SDK Sample , wherein the context is used.

Please Register or Login to post a reply

1 Replies

J James Swinton-Bland

Hi Haresh,
Thanks for your positive feedback.
To answer your questions:

I would recommend retaining an instance of the RFIDHandler in your Activity rather than creating a new instance for each fragment. The RFIDHandler class will attempt a re-connenection every time a new instance is created, which wouldn't be ideal.
I would create an interface to manage communication between your activity and fragments & trigger RFID reads via the interface. Simply don't implement this interface in the fragments that don't require RFID reading.
You can either disconnect from the reader entirely, or simply ignore reads. 

CONTACT
Can’t find what you’re looking for?