Android Question Activity or Service

b4auser1

Well-Known Member
Licensed User
How to determine the context of current Sub: if the current Sub is called from Service or from Activity ?
I need this information to call MsgBox (if Activity) or Log(if Service).
 

eurojam

Well-Known Member
Licensed User
you can add a parameter to the sub like
B4X:
sub HelloWorld (param1 as Parameter, CallingFrom as String)
If CallingFrom = "Activity" then
  MsBox(...)
else
  log(...)
end if
...
end sub
but it is not a real detection....just an idea
 

b4auser1

Well-Known Member
Licensed User
Thank you. But passing context as an argument thru many Subs is not very convinient :(
 

b4auser1

Well-Known Member
Licensed User
Thank you.
I tested the code and it resolved my problem, because it returns name of Activity/service even if called from class or code module.
 
Top