Android Question How to pass current activity as parameter

shantharam

New Member
Licensed User
Longtime User
I have seen the following code under thread - Take Screenshot in B4A version 2.0 (posted by another user)

Sub TakeScreenshot (Activity As Activity)

My question is how do I pass the current activity as a parameter to the subroutine TakeScreenshot(Activity as Activity)

Any help is appreciated. In Java I believe the this reference will do the trick but how to pass the Main activity to this subroutine.

The code for the subroutine is as follows
Sub TakeScreenshot (activity As activity)
Log("TakeScreenshot activated")
' Take a screenshot.

Dim Obj1, Obj2 As Reflector
Dim bmp As Bitmap
Dim c As Canvas
Dim now, i As Long
Dim dt As String
DateTime.DateFormat = "yyMMddHHmmss"
now = DateTime.now
dt = DateTime.date(now) ' e.g.: "110812150355" is Aug.12, 2011, 3:03:55 p.m.
Obj1.Target = Obj1.GetActivityBA
Obj1.Target = Obj1.GetField("vg")
bmp.InitializeMutable(activity.Width,activity.Height)
c.Initialize2(bmp)
Dim args(1) As Object
Dim types(1) As String
Obj2.Target = c
Obj2.Target = Obj2.GetField("canvas")
args(0) = Obj2.Target
types(0) = "android.graphics.Canvas"
Obj1.RunMethod4("draw", args, types)
Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, dt & ".png", False)
bmp.WriteToStream(Out, 100, "PNG")
Out.close
ToastMessageShow("Screenshot Captured", False)
End Sub
 

shantharam

New Member
Licensed User
Longtime User
Thanks Erel for the reply. Will use the code tag for future questions.

With regards to the above question the sub is not in the activity module but in a separate module so that it can be reused between multiple activities. In that case how can the activity be passed. Any help is appreciated.
 
Upvote 0
Top