Android Question Fun with serial barcode reader

nibbo

Active Member
Licensed User
Longtime User
OK, hard one to explain here unless you are using my app but I will try.

I have an app that uses a bluetooth barcode scanner in serial mode which connects just fine and passes the data back using AsyncStreams_NewData event.

My problem is that I want to be able to use the scanner and read the stream data in more than one activity.
Currently if I am in the activity where the connection was made and the AsyncStream is initialised everything works fine.
If however I start another activity and scan something it waits until it gets back before firing the NewData event, which makes sense.
How can I make it such that I am able to use the scanner in a couple of different activities? Is this even possible?

Thanks
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I accomplish this by handling the SPP-mode input data in the Starter service (technically, the barcode scanner code is its own class which the Starter service manages), with the following code-flow:

  1. Each activity sets a global starter service string variable called "CurrentActivity" in it's activity resume event to it's name (e.g. "Activity2", "actLogin", etc).
  2. In the starter's _NewData event, I check to see if the "CurrentActivty" <> "" then if it is not:
  3. I check "IsPaused(CurrentActivity)" and if not then:
  4. I check for SubExists(CurrentActivity, "Barcode_Scanned") and if it does:
  5. CallSubDelayed2(CurrentActivity, "Barcode_Scanned", AsyncDataReceived)
This way it is up to each activity to implement the "Barcode_Scanned" event to suit its own purposes.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
OR just switch to B4XPages and don´t care about such issues any longer.
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
OR just switch to B4XPages and don´t care about such issues any longer.
If only I had time for such things, I haven't even had time to look at B4XPages yet :(
This is an old app with 15 activities, I am guessing it would take a while to convert?
 
Upvote 0
Top