Java Question how I can caller callsub function from Java library?

Roberto P.

Well-Known Member
Licensed User
Hi All,

I created a library in Java and I need to know how to use the "CallSub" function to call a function that is in the application.

I hope it is clear.

thank in advance
Regards
 

Roberto P.

Well-Known Member
Licensed User
I don't make a call to the UI, but at procedure that is launched.

I don't found any examples with BA.raiseEventFromUI
 

Semen Matusovskiy

Well-Known Member
Licensed User
To understand internals, you can look java modules inside Objects subfolder.
Unlike B4A doesn't offer official way, to call in both directions is enough simple.

For instance (tested in B4A 8.3 only):

B4X:
#BridgeLogger : true

Sub Process_Globals

   Private NativeMe As JavaObject

End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean) 
 
   If FirstTime Then NativeMe.InitializeContext
      Dim stringParameter As String = "Hello World!"
      Dim longParameter   As Long   = -123456789012345678   
      Dim stringReply As String = NativeMe.RunMethod ("FirstMethod", Array (stringParameter, longParameter))   
      Log (stringReply) 'will print "String = Hello World! Long = -123456789012345678"

End Sub

Sub SecondMethod (stringParameter As String, longParameter As Long)   
   
    Log ("String = " & stringParameter & "  Long = " & longParameter) ' will print "String = *** Hello World!  Long = -123456789000000000"
   
End Sub

#If JAVA
public String FirstMethod (String Text, long Value) {   
   try { _secondmethod ("*** " + Text, Value + 12345678); } catch (Exception e) { return ""; };
   return "String = " + Text + " Long = " + Value;
}
#End If
 

Roberto P.

Well-Known Member
Licensed User
I thank you for the suggestion, but this is not the case. because my library was written all in Java. So, I have to find a way to send a message to the application written with B4A

I hope it is clear
thank
 

DonManfred

Expert
Licensed User

Dabzy1978

Member
Licensed User
So, you have an application written in Java, which uses your library, this is on your desktop, and you want to fling a message to an app on a device thats built with B4A?

Could you not use TCP/IP to communicate between them both?

https://www.b4x.com/android/help/network.html

Or do you require, say a C++ application calling an external function in a DLL kinda setup?

Its been a long day at work and I'm confused.com, but thought I'd throw that in there!

Dabz
 
Last edited:

Roberto P.

Well-Known Member
Licensed User
Hi all
summarize, I managed to launch the call with the following steps
B4X:
1 - declare events
@Events(values={"end_fiscal_printer", "end_not_fiscal_printer"})

2-declare variables
    protected BA         m_ba;
    protected Object     m_Object;

3-assign value at variables
public void Inizialize(BA ba) {
                
            // valorizzo il parametro
            this.m_ba         = ba;
            this.m_Object    = ba;
        }

4-trigger event
 if (m_ba.subExists("end_not_fiscal_printer")) {
    m_ba.raiseEvent(m_Object, "end_not_fiscal_printer");
    }

functions are case sensitive, better to use all lowercase

I thank everyone for help
 
Top