Android Question Capture error when disconnecting a BLUETOOTH device

netsistemas

Active Member
Licensed User
Longtime User
On my phone and also tablet, I have connected a Bluetooth barcode reader that simulates keystrokes directly. Without installing anything.
So far everything is OK.
The problem is that when the device is disconnected and/or connected, my B4XPages application gives some type of error that I do not detect and the application restarts.
How do I detect and prevent this error?
 

netsistemas

Active Member
Licensed User
Longtime User
I think my problem is related to this thread:

I think it is not an error, but rather the disapear event is launched and the MainPage page opens and I don't know why.


** Activity (main) Pause event (activity is not paused). **
*** paginasalidas: B4XPage_Disappear [mainpage, paginamainmenu, paginasalidas]
** Activity (main) Create **
#SupportedOrientations attribute must be set to landscape or portrait.
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
App ARRANCADA con Conexion

(the last message is my LOG("App ARRANCADA con Conexion")
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
I don't see any errors, or it is captured without being shown


** Activity (main) Pause event (activity is not paused). **
*** paginasalidas: B4XPage_Disappear [mainpage, paginamainmenu, paginasalidas]
** Activity (main) Create **
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** mainpage: B4XPage_PermissionResult [mainpage]
App ARRANCADA con Conexion

i include
B4X:
    Dim btAdmin As BluetoothAdmin 'SERIAL
    Dim cmp20 As Serial
    Dim printer As TextWriter

in b4xMaingPage

and
B4X:
    btAdmin.Initialize("BlueTeeth")
        'mp20.Initialize("Printer")
    cmp20.Initialize("Printer")
    wait for (PermisoPrint) complete (Rt As Boolean)
       
    StartPrinter

in B47xMaingPage B4xPage_Created

But it's curious, when the bluetooth of my device is activated or deactivated (not on the phone, but on the BARCODE READE device)
The event is executed again:

B4xPage_Created
in B4AxMainPage

I understand that this code should only be executed once, unless there is an error restart of the application. But I don't know
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
FIRST RUN:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
*** mainpage: B4XPage_Appear <---------------------------------------------------------------------------------view down agaiin
** Activity (main) Resume **
*** mainpage: B4XPage_PermissionResult [mainpage]
App ARRANCADA con Conexion
App ARRANCADA con Conexion
App ARRANCADA con Conexion
App ARRANCADA con Conexion
*** paginamainmenu: B4XPage_Created [mainpage]
*** mainpage: B4XPage_Disappear [mainpage]
*** paginamainmenu: B4XPage_Appear [mainpage]
** Activity (main) Pause event (activity is not paused). **
*** paginamainmenu: B4XPage_Disappear [mainpage, paginamainmenu]
** Activity (frmgetclave) Create (first time) **
** Activity (frmgetclave) Resume **
*** paginasalidas: B4XPage_Created [mainpage, paginamainmenu]
** Activity (frmgetclave) Pause, UserClosed = true **
** Activity (main) Resume **
*** paginasalidas: B4XPage_Appear [mainpage, paginamainmenu, paginasalidas]
App ARRANCADA con Conexion
** Activity (main) Pause event (activity is not paused). **
*** paginasalidas: B4XPage_Disappear [mainpage, paginamainmenu, paginasalidas] <------------------(WHEN BLUETOOTH BARCODE CONNECT)
** Activity (main) Create **
*** mainpage: B4XPage_Appear <---------------------------------------------------------------------------------
** Activity (main) Resume **
*** mainpage: B4XPage_PermissionResult [mainpage]
App ARRANCADA con Conexion
App ARRANCADA con Conexión
....
...
...
...
----------------------------------------------(restart bluetooth)(navegate to my 3# form and off bluetoot (5 minutes))
** Activity (main) Pause event (activity is not paused). **
*** paginasalidas: B4XPage_Disappear [mainpage, paginamainmenu, paginasalidas]
** Activity (main) Create **
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** mainpage: B4XPage_PermissionResult [mainpage]
App ARRANCADA con Conexion
App ARRANCADA con Conexion
----------------------------------------------(restart bluetooth)
** Activity (main) Pause event (activity is not paused). **
*** mainpage: B4XPage_Disappear [mainpage]
** Activity (main) Create **
*** mainpage: B4XPage_Appear
** Activity (main) Resume **
*** mainpage: B4XPage_PermissionResult [mainpage]
App ARRANCADA con Conexion
App ARRANCADA con Conexion





It seems that when you disconnect the Bluetooth device that is on, it does so after 5 minutes, the B4XPage_Disappear skips and all the loaded PAGES disappear.
Then the:
** Activity (main) Create **
(no longer firsttime)

and then he
*** mainpage: B4XPage_Appear
with which it seems that the application has been restarted

Tomorrow I will try another Bluetooth reader and if there is no other option, I will buy a reader that can set the time to more than the 5 minutes I have now.
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Longtime User
Perhaps try communicating with the barcode reader once every less-than-five minutes, so that it doesn't feel ignored and chuck a hissy fit.

Or is it that the barcode reader is communicating via an intent or similar, and doesn't realise your app is already running, so it starts up a new instance of it?

Just brainstorming here. I have no experience with barcode readers and Android. But sometimes a random stupid idea can trigger a better idea.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
in my experience, bluetooth devices acting as HID
can trigger a broadcast when connected or disconnected.
this can cause the app to restart. some might consider
this an error. in addition, the device is set to disconnect/turn
off automatically after a certain time. whether adding a
broadcast receiver will help, you'd have to try. in my case,
it's not an issue (for a number of reasons). android, being
android, may not even recognize the receiver.
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
The barcode reader has nothing to do with my application.
Once you link it, the system simulates text entry as if it were a keyboard.
I'm sure the application doesn't restart.

What happens is that the 'B4XPage_Disappear' event is triggered, and then the 'B4XPage_Appear' but at this point all the loaded PAGES have disappeared, showing the initial one.


It also happens in NON-B4XPAGES applications, but since there is no PAGE management in this new model of pages, the page where it was simply reloads and nothing special happens or at least, it would be easy to control it, because it is like when you turn the phone.

The READER has seen that he has the option to extend the time, so I will do it so that my client can work a little more comfortably.
I have also added a control to know if it is the first time that the main PAGE is opened or not, and thus not ask the user for password validation, and at least the main menu appears. You could implement a stack of open PAGES and reopen them in this situation, but I guess I think it's important to know what happens.
 
Upvote 0
Top