#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Timer1 As Timer
Dim ActMan As JavaObject
End Sub
Sub Service_Create
Timer1.Initialize("Timer1",1000)
End Sub
Sub Service_Start (StartingIntent As Intent)
Timer1.Enabled = True
Dim R As Reflector
R.Target=R.GetContext
ActMan = R.RunMethod2("getSystemService","activity","java.lang.String")
End Sub
Sub Service_Destroy
Timer1.Enabled = False
End Sub
Sub Timer1_Tick
'From http://stackoverflow.com/questions/3873659/android-how-can-i-get-the-current-foreground-activity-from-a-service
Dim TaskInfo As JavaObject = ActMan.RunMethod("getRunningTasks",Array As Object(1))
Dim CompInfo As JavaObject = TaskInfo.RunMethodJO("get",Array As Object(0)).GetField("topActivity")
Dim PackageName As String = CompInfo.RunMethod("getPackageName",Null)
Log(PackageName)
End Sub