B4A Tutorial Inline Java Code - Erel    
Feb 24, 2022   
(171 reactions)   
tags: Code, Java, inline java codeThe next versions of B4A (4.30) and B4J (2.80) will allow you to embed Java code inside your... to access third party SDKs and also to allow developers to add existing Java code snippets to their projects.
Adding Java code is done with an #If Java block:
#If JAVA
public String FirstMethod() {
return "Hello World!";
}
#End If
You need an instance of JavaObject to access the Java methods:
Sub Process_Globals
Private NativeMe As JavaObject
End Sub
Sub Globals
End Sub...
B4A Code Snippet Implementing a callback with inline Java - Erel    
Oct 3, 2025   
(15 reactions)This is a template that you can use when implementing a callback with inline Java, whether it is an interface or abstract class, inside a B4A/B4J class, such as B4XMainPage.
#if Java
public static...
link: This is really not the correct place for this question. Start a new thread instead.
And the context...
link:
The code should be added to a class module. It will work with non-B4XPages classes.
Hi,
In this P...
link:
Is the code specific to B4XPages? An example would be of real benefit.
The code should be added to...
Beta Can we use ba.raiseEvent from inline java code? - stevel05    
Feb 2, 2015Is it possible to use ba.raiseEvent to call a callback sub in the enclosing Activity,class,service or code module? It doesn't give an error, just no result either.
In a class, I've tried:
Sub DoMultiply
nativeMe.RunMethod("Multiply", Array ("logresult",10))
End Sub
Sub LogResult(Result As Int)
Log(Result)
End Sub
#If JAVA
private int mm = 100;
public void Multiply(String EventName,int i) {
int result = i * 2 + mm;
if(ba.subExists(EventName...
B4A Code Snippet Using Java 8+ lambdas with inline Java code - Erel    
Apr 17, 2024   
(8 reactions):
#AdditionalJar: core-lambda-stubs.jar, ReferenceOnly
Example:
'in B4XPage
#if java
import java....forEach( (n) -> BA.Log("" + n) );
}
#End If
Me.as(JavaObject).RunMethod("test...
link:
As 'Me' doesn't appear to have .As as a method.
This is an IDE bug. You can use As wit...
link: Is it
Me.As(JavaObject). ...
or
(Me).As(JavaObject). ...
As 'Me' doesn't appear...
link: inline code inside activities....
B4A Question Create a broadcast receiver when app loads using inline java - Jmu5667    
Apr 16, 2015Hi All
I have a app that uses a few intent filters. They are currently setup in manifest file. Example
' // Power Intents
AddReceiverText(svc_power, <intent-filter> <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/></intent-filter>)
AddReceiverText(svc_power, <intent-filter> <action android:name="android.intent.action.ACTION_POWE...
B4A Question Inline Java - GiovanniPolese    
Aug 2, 2023Hi to All
I have some java code that might be useful in my project. I was thinking to insert it with the "#if JAVA ... #end if" paradigm.
As a first step, I created a B4XPages project and...
link: addition) to #If Java #End If , it's possible to mark inline Java statements by special symbol. For...
link:
Using
myClass.InitializeNewInstance(GetType(Me) & "$" & "SimpleTest",N...
link: Using
myClass.InitializeNewInstance(GetType(Me) & "$" & "SimpleTest",N...
B4A Example Take a Screenshot with Inline Java Code - Johan Schoeman    
Dec 2, 2017   
(10 reactions)I have tested this on an Android 7.0 device only - take a screenshot of your activity. You need to enable the JavaObject library to make use of it.
@JordiCP solved my initial problem here (thanks @JordiCP):
https://www.b4x.com/android/forum/threads/passing-b4a-activity-to-inline-java-code.86796... be accessed from this module.
Dim nativeMe As JavaObject
Private Button1 As Button
Private iv1...
End Sub
#If Java
import android.app.Activity;
import android.graphics.Bitmap;
import android...
B4A Question Inline Java. Why does this code fail both with word 'static' and without 'static'? - hatzisn    
Jul 20, 2026   
(1 reaction) and it fails both with adding the word "static" in the inline JAVA functions and without...
link: Thank you both. I used both solutions for this library. You can find it here:
https://www.b4x.com/a...
link: Sub
Since the inline Java is within a Class (not Activity/Service/Module), don't use static...
link: As Object(r.GetContext))
Return sRet
End Sub
Or move the inline java into Main module....
B4A Tutorial Firebase RealtimeDatabase B4A interaction with Inline Java code Part - 1 - jkhazraji    
Oct 26, 2026   
(5 reactions) (FBBridge)
Private fbBridge As JavaObject
Define the class in inline Java:
import com.google...();
String json = value == null ? "{}" : new JSONObject((java.util.Map) value).toString...
Share My Creation CircleCheckBox [inline Java] - jkhazraji    
May 11, 2026   
(7 reactions).
Private xui As XUI
Private context As JavaObject
Dim CircleCheckBox As JavaObject
End Sub... As Object = CircleCheckBox.As(JavaObject).CreateEventFromUI(Application.PackageName & _
".main....As(JavaObject).RunMethod("setOnCheckedChangeListener",Array(event))
End Sub
Sub... GetBA As JavaObject
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString...
link: what goes around, comes around. @Johan Schoeman wrapped this as a b4a library 10 years ago. looks like even he forgot. he's always ahead of the curve....
Page: 1  
2  
3  
4  
5  
6  
7