I have a class file name funcs, and there is a code like this
B4X:
Public Sub statusBarColor(color As Int)
If ph.SdkVersion >= 21 Then
Dim jObj As JavaObject
jObj.InitializeContext
Dim window As JavaObject = jObj.RunMethodJO("getWindow", Null)
window.RunMethod("addFlags", Array (0x80000000))
window.RunMethod("clearFlags", Array (0x04000000))
window.RunMethod("setStatusBarColor", Array(color))
End If
End Sub
and i defined it to main activity in process_globall
The class was defined in all activities, and there was no problem.
When i decide to remove all of them (class definitons) and calling from in main activity, problem was occured.
Javaobject knows only "main activity" not the others
Yeah, it doesn't work like that. What you could do is to create new Code Module and add all necessary code into it.
You can change color from every Activity by using StatusBarColor method in Code Module. That's how different Activities can share same code.
Public Sub statusBarColor(jObj As JavaObject,color As Int)
If ph.SdkVersion >= 21 Then
Dim window As JavaObject = jObj.RunMethodJO("getWindow", Null)
window.RunMethod("addFlags", Array (0x80000000))
window.RunMethod("clearFlags", Array (0x04000000))
window.RunMethod("setStatusBarColor", Array(color))
End If
End Sub
definition in Main activity
B4X:
Sub Process_Globals
Public f As funcs
End Sub
and calling in another activity
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim jObj As JavaObject
jObj.InitializeContext
Main.f.statusBarColor(jObj,Colors.RGB(127, 83, 124))
End Sub
Because class cant understand the current context, i'm sending
Class understands current context very well.
Something talks me that you didn't initialize class object
Meanwhile https://www.b4x.com/android/forum/threads/classes-tutorial.18626/ talks Initialize - A class object should be initialized before you can call any other sub. Initializing an object is done by calling the Initialize sub. When you call Initialize you set the object's context (the parent activity or service).
I initialized it in Main activity too, and the others activities run
i think there is no need to initialize again and again, whatever it is running now
thank you for all,
Best regards
you're absolutely right dear @Semen Matusovskiy
and i understood it with this app if the class uses context, it has only general functions except statusBarColor