Jul 5, 2016 Replies: 7 If you're in a code module, you don't have the Activity object handy to reference. Here's a simple sub (courtesy of Erel) that fetches the current B4A activity: Code: Copy Sub getCurrentActivity As Activity Dim r As Reflector r.Target = r.GetActivityBA Return r.GetField("vg") End Sub Click to expand...
If you're in a code module, you don't have the Activity object handy to reference. Here's a simple sub (courtesy of Erel) that fetches the current B4A activity: Code: Copy Sub getCurrentActivity As Activity Dim r As Reflector r.Target = r.GetActivityBA Return r.GetField("vg") End Sub
lemonisdead Well-Known Member Licensed User Longtime User Jul 5, 2016 #2 Thanks. What does "vg" stand for ? Thanks
Erel B4X founder Staff member Licensed User Longtime User Jul 6, 2016 #3 This is an internal field that points to the Activity view.
S swabygw Active Member Licensed User Longtime User Dec 17, 2016 #4 I know this is an old thread, but I could use this. However, when I run it in my Activity, I get the following: "(BALayout): Layout not available". This is my execution (within Activity_Create section): Code: Copy Log("act:" & getCurrentActivity)
I know this is an old thread, but I could use this. However, when I run it in my Activity, I get the following: "(BALayout): Layout not available". This is my execution (within Activity_Create section): Code: Copy Log("act:" & getCurrentActivity)
Erel B4X founder Staff member Licensed User Longtime User Dec 18, 2016 #5 You can ignore this message.
peacemaker Expert Licensed User Longtime User Jul 8, 2017 #6 So, each Activity must contain this sub ? No way to detect from the single sub the current active Activity ?
So, each Activity must contain this sub ? No way to detect from the single sub the current active Activity ?
Alpandino Member Licensed User Jul 19, 2017 #8 I tried to use this code in a service, but I receive this error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference I tried in both cases: app in foreground and app in background. Maybe I can't use this code in a service?
I tried to use this code in a service, but I receive this error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference I tried in both cases: app in foreground and app in background. Maybe I can't use this code in a service?