Android Question Javaobject.InitializeContext inside Starter

Semen Matusovskiy

Well-Known Member
Licensed User
It seems to me this does not work in current B4A releases (unlike works fine for activities and another services).

What is correct replacement ? Or when we can expect changes in JavaObject.jar ?
 

Semen Matusovskiy

Well-Known Member
Licensed User
Call it in Service_Create and store it with a global variable.

Are you sure ? I talk exactly about Starter service.

According my experiments (in Service_Create event) jo.InitializeContext returns application relative object (Application) android.app.Application@12c0a56

If to use "GetBA" code
B4X:
Dim cls As String = Me   
cls = cls.SubString("class ".Length)
joStarterA.InitializeNewInstance (cls, Null)
joStarterA.GetField ("processBA")
jo will be (starter) b4a.example.starter@c7aac71 and this works in jo.RunMethod ("inlinejava-sub", ...)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It depends on what you are trying to do with the returned object. It returns the application context.

If you want to call an inline Java method from the starter service then you can do it with:
B4X:
Sub Service_Create
   Dim jo As JavaObject = Me
   Log(jo.RunMethod("test", Null))
End Sub

#if Java
public static int test() {
   return 100;
}
#End If
 
Upvote 0
Top