Android Question Problem with StartActivityForResult return result

TheMightySwe

Active Member
Licensed User
Longtime User
Hi,

We have a java app that connects to a Cardterminal that has the name "se.iqpd.checkout.companion". We start that in B4A with the following code.

B4X:
Dim ISMP_Intent As Intent
    Dim InstalledPackages As PackageManager
    ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")
    ISMP_Intent.PutExtra("JobId","31271")
    ISMP_Intent.PutExtra("TransactionType","Purchase")
    ISMP_Intent.PutExtra("Amount",NumberFormat2(SubTotal_Double-SubTotal_Discount_Double,1,2,2,False))
    StartActivityForResult(ISMP_Intent)

We send the return with following JAVA-code

B4X:
Intent output = new Intent();
            output.putExtra("RESULT", RESULT_OK);
[....] ' Lots of  otherresultdata that we cant post because of confidentiallity agreement  
            getParent().setResult(Activity.RESULT_OK, output);
            finish();


But in B4A we get a error, nothing returns.

main_companion_event (B4A line: 1984)
ResultCode = Args(0)
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at se.iqpd.checkout.plus.main._companion_event(main.java:4069)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4j.object.JavaObject$1.invoke(JavaObject.java:191)
at $Proxy0.toString(Native Method)
at java.lang.String.valueOf(String.java:1649)
at anywheresoftware.b4a.debug.Debug.objectToString(Debug.java:384)
at anywheresoftware.b4a.debug.Debug.writeGlobals(Debug.java:303)
at anywheresoftware.b4a.debug.Debug.sendBPData(Debug.java:284)
at anywheresoftware.b4a.debug.Debug.access$9(Debug.java:279)
at anywheresoftware.b4a.debug.Debug$1.run(Debug.java:256)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:200)
at anywheresoftware.b4a.Msgbox.debugWait(Msgbox.java:158)
at anywheresoftware.b4a.debug.Debug.wait(Debug.java:213)
at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:260)
at anywheresoftware.b4a.debug.Debug.ShouldStop(Debug.java:232)
at se.iqpd.checkout.plus.main._unitevents_batterychanged(main.java:23572)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.phone.PhoneEvents$ActionHandler$1.run(PhoneEvents.java:321)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)


Why is that, anyone knows?

// TMS
 

TheMightySwe

Active Member
Licensed User
Longtime User
Can you upload your code?

This is the B4A part.

B4X:
#Region Companion

Sub GetBA As Object

   Dim jo As JavaObject
   Dim cls As String = Me
   cls = cls.SubString("class ".Length)
   jo.InitializeStatic(cls)
   Return jo.GetField("processBA")
  
End Sub

Sub StartActivityForResult(CompanionIntent As Intent)
   Dim jo As JavaObject = GetBA
   Companion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "Companion", Null)
   jo.RunMethod("startActivityForResult", Array As Object(Companion, CompanionIntent))
End Sub

Sub Companion_Event(MethodName As String, Args() As Object) As Object

    Dim ResultCode As Int
    Dim ResultIntent As Intent
   
    ResultCode = Args(0)
    ResultIntent = Args(1)
   
    Return Null

End Sub

Sub IsCompanionAvailible As Boolean

    If IsIQPDCompanionApplicationInstalled = True AND IsPayexCompanionServiceInstalled = True Then
        ISMP.IsAvailible = True
        Return True
    Else
        ISMP.IsAvailible = False
        Return False
    End If

End Sub

Sub IsIQPDCompanionApplicationInstalled As Boolean

    Dim InstalledPackages As PackageManager
    InstalledPackages.GetInstalledPackages()
   
    Dim Packages As List
    Packages = InstalledPackages.GetInstalledPackages
   
    For i = 0 To Packages.Size - 1
        If Packages.Get(i) = "se.iqpd.checkout.companion" Then Return True
    Next
   
    Return False

End Sub

Sub IsPayexCompanionServiceInstalled As Boolean

    Dim InstalledPackages As PackageManager
    InstalledPackages.GetInstalledPackages()
   
    Dim Packages As List
    Packages = InstalledPackages.GetInstalledPackages
    For i = 0 To Packages.Size - 1
        If Packages.Get(i) = "com.ingenico.pclservice" Then Return True
    Next
   
    Return False

End Sub

Sub ISMPCompanionDoPurchase

    If IsCompanionAvailible = False Then
        Return
    End If

    If IsNumber(SubTotal_Double-SubTotal_Discount_Double) = False Then Return
   
    If CodeSnippets.IsNegative(SubTotal_Double-SubTotal_Discount_Double) = True Then Return

    Dim ISMP_Intent As Intent
    Dim InstalledPackages As PackageManager
    ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")
    ISMP_Intent.PutExtra("JobId","31271")
    ISMP_Intent.PutExtra("TransactionType","Purchase")
    ISMP_Intent.PutExtra("Amount",NumberFormat2(SubTotal_Double-SubTotal_Discount_Double,1,2,2,False))
    StartActivityForResult(ISMP_Intent)

End Sub

Sub ISMPCompanionDoCashback

    If IsCompanionAvailible = False Then
        Return
    End If
   
    If IsNumber(SubTotal_Double-SubTotal_Discount_Double) = False Then Return
    If IsNumber(SubTotal_Cashback_Double) = False Then Return

    If CodeSnippets.IsNegative(SubTotal_Double-SubTotal_Discount_Double) = True Then Return
    If CodeSnippets.IsNegative(SubTotal_Cashback_Double) = True Then Return

    Dim ISMP_Intent As Intent
 
    Dim InstalledPackages As PackageManager
    ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")

    ISMP_Intent.PutExtra("JobId","0")
    ISMP_Intent.PutExtra("TransactionType","Cashback")
    ISMP_Intent.PutExtra("Amount",NumberFormat2(SubTotal_Double-SubTotal_Discount_Double,1,2,2,False))
    ISMP_Intent.PutExtra("ExtraAmount",NumberFormat2(SubTotal_Cashback_Double,1,2,2,False))
    StartActivityForResult(ISMP_Intent)

End Sub

Sub ISMPCompanionDoRefund

    If IsCompanionAvailible = False Then
        Return
    End If

    If IsNumber(CodeSnippets.ConvertToPositive(SubTotal_Double)) = False Then Return

   Dim ISMP_Intent As Intent
  
   Dim InstalledPackages As PackageManager
   ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")
   ISMP_Intent.PutExtra("JobId","0")
   ISMP_Intent.PutExtra("TransactionType","Refund")
   ISMP_Intent.PutExtra("Amount",CodeSnippets.ConvertToPositive(SubTotal_Double))
  
   StartActivityForResult(ISMP_Intent)

End Sub

Sub ISMPCompanionDoReversal

    If IsCompanionAvailible = False Then
        Return
    End If

   Dim ISMP_Intent As Intent
   Dim InstalledPackages As PackageManager
   ISMP_Intent = InstalledPackages.GetApplicationIntent("se.iqpd.checkout.companion")
   ISMP_Intent.PutExtra("JobId","0")
   ISMP_Intent.PutExtra("TransactionType","Reversal")
   StartActivityForResult(ISMP_Intent)

End Sub

#End Region

Unfortuanally you need hardware to run the JAVA part, but i'll ask our JAVA-guy to upload the JAVA part.
 
Upvote 0

TheMightySwe

Active Member
Licensed User
Longtime User
B4X:
  Log(Args)
    Log("Args length : " & Args.Length)

Gives

[Ljava.lang.Object;@2168f368
Args length : 2

Error is

main_companion_event (B4A line: 1992)
ResultCode = Args(0)
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
at se.iqpd.checkout.plus.main._companion_event(main.java:4094)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4j.object.JavaObject$1.invoke(JavaObject.java:191)
at $Proxy0.toString(Native Method)
at java.lang.String.valueOf(String.java:1649)
at anywheresoftware.b4a.debug.Debug.objectToString(Debug.java:384)
at anywheresoftware.b4a.debug.Debug.writeGlobals(Debug.java:303)
at anywheresoftware.b4a.debug.Debug.sendBPData(Debug.java:284)
at anywheresoftware.b4a.debug.Debug.access$9(Debug.java:279)
at anywheresoftware.b4a.debug.Debug$1.run(Debug.java:256)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:200)
at anywheresoftware.b4a.Msgbox.debugWait(Msgbox.java:158)
at anywheresoftware.b4a.debug.Debug.wait(Debug.java:213)
at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:260)
at anywheresoftware.b4a.debug.Debug.ShouldStop(Debug.java:232)
at se.iqpd.checkout.plus.main._companion_event(main.java:4105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4j.object.JavaObject$1.invoke(JavaObject.java:191)
at $Proxy0.ResultArrived(Native Method)
at anywheresoftware.b4a.BA$5.run(BA.java:505)
at anywheresoftware.b4a.BA.setActivityPaused(BA.java:390)
at se.iqpd.checkout.plus.main$ResumeMessage.run(main.java:271)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
 
Upvote 0

TheMightySwe

Active Member
Licensed User
Longtime User
This is the errors that we get when we try to access the object containing the result. But since we get ArrayIndexOutOfBoundsException it seems like we dont send anything back from our java application.
 
Upvote 0

TheMightySwe

Active Member
Licensed User
Longtime User
Yes and that is something we dont get, returns length 2 but still get ArrayIndexOutOfBoundsException when we try to access the array.
 
Upvote 0
Top