Android Question sending message to waiting queue [SOLVED]

nibbo

Active Member
Licensed User
Longtime User
Can anyone explain what causes the above message in the logs?

I have a barcode scanner manager class which is created in the starter service. Everything seems to work OK (connect events etc..) until I scan a barcode.
Every time I scan a barcode I get the message
sending message to waiting queue (scannerstream_newdata)

The newdata event does not fire when in an activity other that main! When I click the back button until I reach the Main activity all of the barcode scans come flooding through...

I don't really understand what the message is saying!

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Where is the relevant Code?

Are you using the scannerstream in an Activity which is paused?
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
Where is the relevant Code?
Are you using the scannerstream in an Activity which is paused?

Hi DonManfred

Thanks but which bit of code would be of interest? It's a largish project with 4 activities, a class for the scanner and the starter service.
The scannerStream is part of the scannerManager class which is instantiated in the starter service (based on Erels bluetooth chat example).

If I scan a barcode while in Main the NewData event fires OK, in any other activity I get the 'sending message to waiting queue...'

The 'current' activity is not paused (not that I am aware of).

I am assuming that because it declared as public in Process_Globals of the Starter service it should be available at all times?

Maybe I need to trim it down to the basics and post a sample project?

Thanks
Nibbo
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
It looks like the scanner is queuing messages that are released by some mechanism when the correct activity to handle them is resumed. Where this mechanism is I can't guess without further information.

Why not try putting the scanner class instance in the activity rather than the Starter service?
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
Why not try putting the scanner class instance in the activity rather than the Starter service?

I want the scanned barcode to be available to several activities not just one.
This is going to be a warehouse management app so the user could be doing any one of a half a dozen tasks (activities).
When I receive new data I want to call the relevant sub in whatever the current activity is.

Thanks
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
OK, then you have not provided enough information on the structure of your app and how you expect to delegate the scanner events to those different activities.

Thanks again

Below is the code in the scanner class newdata:

B4X:
Private Sub scannerStream_NewData (Buffer() As Byte)
    Dim sCode As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    Log(sCode)
    If Main.CurrentActivity <> "" And Not(IsPaused(Main.CurrentActivity)) Then
        If SubExists(Main.CurrentActivity, "BarcodeScanned") Then
            CallSubDelayed2(Main.CurrentActivity, "BarcodeScanned", sCode)
        End If
    End If
End Sub

CurrentActivity is a global variable in Main which is set in the Activity_Resume of all subsequent activities.
If... the event fired then it checks which activity I am in, checks to see if the activity has a sub called BarcodeScanned and calls it.
Unfortunately it does not fire until I get back to Main

I will try to reproduce it in a smaller project and upload it.

Thanks
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
Managed to recreate the problem in a small project but :eek:
How can I upload it? Its only 773KB but I am told 'The uploaded file is too large' 😭
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I'm stuck I'm afraid. It looks too me as your code ought to work, though with Callsub to call the Sub directly and not go through the message loop. Though I can't immediately see why in your case all the CallSubDelayed calls end up in the Main module message loop - which is what your original message is telling you.
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
OK, removed all comments, blank lines and unused parts of the scannerManager and it uploads now...
Thanks
 

Attachments

  • barcodeTest.zip
    137.4 KB · Views: 122
Upvote 0

agraham

Expert
Licensed User
Longtime User
I won't try to describe everything I've tried , I can't see the original problem as I don't have a scanner, but that event vectoring code seems to work in Starter but not the ScannerManager class.

Try copying the ScannerManager.scannerStream_NewData to Starter, make it Public and call it as Starter.scannerStream_NewData in ScannerManager.scannerStream_NewData
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Have you read this explanation of CallSubDelayed?



- currentActivity should not be a string type but Activity type or possibly an Object. I'm surprised that this works.

Based on Erel's post, it looks like all is working as expected. Main is in the background and the messages are being held until main is in the foreground.

I would put the Variable currentActivity either in the Starter service or another service, to ensure that the redirection works.

Like @agraham I could not run the app as it stands, but I made the changes that I believe will make it work.

Finally, B4xPages will remove all of these problems immediately.

Hope this helps.
 

Attachments

  • barcodeTest.zip
    11.7 KB · Views: 126
Upvote 0

agraham

Expert
Licensed User
Longtime User
- currentActivity should not be a string type but Activity type or possibly an Object. I'm surprised that this works.
It absolutely can be a String. There is a getComponentBA method in Core.jar that checks for a String parameter and returns the required component. This is used in most places where you can specify a class or activity.
Main is in the background and the messages are being held until main is in the foreground.
CallSubDelayed should be sending them to the active activity, not Main. That is actually the problem the OP is seeing but I can't replicate though I can get the vectoring to work if I put it in Starter itself.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
My Bad on the Activity. Never done it that way.

CallSubDelayed should be sending them to the active activity, not Main. That is actually the problem the OP is seeing but I can't replicate though I can get the vectoring to work if I put it in Starter itself.

Yes I saw that in the code. I was thinking that because the variable was in main. If main is not active then the redirection does not work either, which is why I suggested using a service.
 
Upvote 0
Top