Semen Matusovskiy Well-Known Member Licensed User Sep 18, 2018 #1 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 ?
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 ?
Erel B4X founder Staff member Licensed User Longtime User Sep 20, 2018 #2 Call it in Service_Create and store it with a global variable. Upvote 0
Semen Matusovskiy Well-Known Member Licensed User Sep 20, 2018 #3 Erel said: Call it in Service_Create and store it with a global variable. Click to expand... 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 Code: Copy 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 said: Call it in Service_Create and store it with a global variable. Click to expand... 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 Code: Copy 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", ...)
Erel B4X founder Staff member Licensed User Longtime User Sep 20, 2018 #4 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: Code: Copy 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
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: Code: Copy 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
Semen Matusovskiy Well-Known Member Licensed User Sep 20, 2018 #5 Thanx, Erel. Dim jo As JavaObject = Me Click to expand... Nice. Looks even better than jo.InitializeContext. Exactly in my case I can use public static. But what to use for instance (non-static) methods ? Upvote 0
Thanx, Erel. Dim jo As JavaObject = Me Click to expand... Nice. Looks even better than jo.InitializeContext. Exactly in my case I can use public static. But what to use for instance (non-static) methods ?
Erel B4X founder Staff member Licensed User Longtime User Sep 20, 2018 #6 Semen Matusovskiy said: But what to use for instance (non-static) methods ? Click to expand... Why do you need to create an instance method? Don't use the starter service for such cases. Upvote 0
Semen Matusovskiy said: But what to use for instance (non-static) methods ? Click to expand... Why do you need to create an instance method? Don't use the starter service for such cases.