Android Question [SOLVED] Call sub from inline Java to paused activity

rosippc64a

Active Member
Licensed User
Longtime User
Hi All,
I integrate the myPOS barcode scanner to my app. The barcode scanner give back to me the result via broadcastreceiver. Works well. But I can't get back the result because "Ignoring event:scan_result. Here is the code:
B4X:
main.b4a
Private Sub btnScanner_Click
    mp.openscanner()
End Sub
'scanner result event
Sub pos_scan_result(success As Boolean,szov As String)
    Log($"Scanner result main ${success} ${szov}"$)
End Sub

myposclass.bas
...
public Sub openscanner
    MEJo.RunMethod("openscanner", Array(GetBA))
End Sub
Sub scan_result(success As Boolean,szov As String)
    Log($"Scan result ${success}"$)
    If SubExists(ParJo,event & "_scan_result") Then
        CallSubDelayed3(ParJo,event & "_scan_result",success,szov)
    Else
        Log($"${event}_scan_result not found!"$)
    End If
End Sub
...

#If JAVA
...

public class ScannerResultBroadcastReceiver extends BroadcastReceiver {

    @SuppressLint("DefaultLocale")
    @Override
    public void onReceive(Context context, Intent intent) {
        String resultCode = intent.getStringExtra("code");
        int status = intent.getIntExtra("status", Activity.RESULT_CANCELED);
        String text = "";
        boolean succ = status == Activity.RESULT_OK;

        if (succ) {
            text = "Scanner result: " + resultCode;
            Toast.makeText(context, "QR kód beolvasva", Toast.LENGTH_SHORT).show();
        } else {
            text = "Scanner cancelled";
        }
        BA.Log(text);
        if(xba.subExists("scan_result")){ 
            BA.Log("scan_result event found");
            //xba.raiseEventFromUI(this,"scan_result".toLowerCase(), succ, resultCode);
'SOLUTION ---------------------->>>>>>>>>>>>>>>
            xba.raiseEventFromDifferentThread(this, this, 0, "scan_result", true, new Object[] { succ, resultCode });

        } else {
            BA.Log("scan_result event not Found");
        }
    }
}
The log:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
_onCreate
myPOSClass initialize. Eventname:pos
** Activity (main) Resume **
'here I click to scanner button****************************
** Activity (main) Pause, UserClosed = false **
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
'the broadcastreceiver receive a lot of message*************
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
'and cant call my scan_result sub!!**************************
Ignoring event: scan_result
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Scanner result: [)>0102113434832916407844286012GEOP660001671249001/0010,00KGNVaci ut 33 BudapestDPD Hungary Kft. [email protected],00KGD007S010DPD Hungary Kft. PUDO+36203499710Vaci ut 33Budapest113434807S020HUF10007S0300DPD Hungary Kft. PUDOVaci ut 33Budapest3481134+362034997100.00HUF348
scan_result event found
Ignoring event: scan_result
Ignoring event: scan_result
** Activity (main) Resume **
The xba.raiseEventFromUI(); does not work 95% of the time, but sometimes it does, I feel that is because my activity is paused.
Question:
How to call event in main module?
How to call sub in a paused module?
thanks in advance
Steven
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Use Callsubdelayed
 
Upvote 0
Top