Activity Object - using in Service or Widget?

cmweb

Active Member
Licensed User
Longtime User
Hello all,

what can I do if I need informations provided by activity objects within a service or a widget?

Example:

I need a reflector to retreive following information:

B4X:
uptime = Obj1.RunStaticMethod("android.os.SystemClock", "uptimeMillis", Null, Null)
elrealtime = Obj1.RunStaticMethod("android.os.SystemClock","elapsedRealtime", Null, Null)

where Obj1 is a reflector.

That does not work, as the a reflector is an activity object.

Is there any solution that allows me to get such data from within a service or a widget?

Thanks for your help.

Best regards,

Carsten
 

cmweb

Active Member
Licensed User
Longtime User
I did use version 1.9.

Now I upgraded to version 2.2 but still getting this error message:

B4X:
Compiling code.                         Error
Error compiling program.
Error description: Process object is expected. {Type=Object,Rank=0} is an Activity object.
Declaring the variable in Sub Globals instead of Sub Process_Globals will solve this problem.
Occurred on line: 75
uptime = obj1.RunStaticMethod("android.os.SystemClock", "uptimeMillis", Null, Null)
Word: null

Any ideas?

Best regards,

Carsten
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
It's a false error from the compiler relating to the use of null that Erel will need to check.

This works fine when a Reflector is Dimmed in either Globals or Process_Globals
B4X:
Dim uptime, elrealtime As Long
Dim args(0) As Object
Dim types(0) As String
uptime = Obj1.RunStaticMethod("android.os.SystemClock", "uptimeMillis", args, types)
elrealtime = Obj1.RunStaticMethod("android.os.SystemClock","elapsedRealtime", args, types)
Msgbox(uptime, elrealtime)

This works when a Reflector is Dimmed in Globals but gives the compiler error when a Reflector is Dimmed in Process_Globals.
B4X:
Dim uptime, elrealtime As Long
uptime = Obj1.RunStaticMethod("android.os.SystemClock", "uptimeMillis", Null, Null)
elrealtime = Obj1.RunStaticMethod("android.os.SystemClock","elapsedRealtime", Null, Null)
Msgbox(uptime, elrealtime)
 
Last edited:
Upvote 0

shaxboz

Member
Licensed User
Longtime User
Hi! I have also like that problem! How can I access to activity object from sub process_globals.
I want to use camera flash from my widget
I am writing Dim mycam As AdvancedCamera, but there is error Cannot access to activity object from process_globals, but there is nor "sub globals" what should I do?
 
Upvote 0
Top