Android Question Activity or Service

Discussion in 'Android Questions' started by b4auser1, Mar 4, 2015.

  1. b4auser1

    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).
     
  2. eurojam

    eurojam Well-Known Member Licensed User

    you can add a parameter to the sub like
    Code:
    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
     
  3. b4auser1

    b4auser1 Well-Known Member Licensed User

    Thank you. But passing context as an argument thru many Subs is not very convinient :(
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    This code will print the full module name of either the service or activity:
    Code:
    Public Sub test
       
    Dim jo As JavaObject
       
    Log(GetType(jo.InitializeContext))
    End Sub
    Are you using many services and activities?
     
    eurojam likes this.
  5. b4auser1

    b4auser1 Well-Known Member Licensed User

     
  6. b4auser1

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice