Getting a package name from OSLibrary's getRecentTasks command

edgeryder1000

Member
Licensed User
Longtime User
Getting a package name from OSLibrary's getRecentTasks (java.util.List)

:sign0163:
For the app I'm making I need to get the package names of the last 4 opened apps. I'm using XverhelstX's OS lib and the command getRecentTasks. My problem is that I don't know how to convert what it returns into the package names of the recent tasks :(

B4X:
OS.getRecentTasks(4,0)
returns something like this:

[android.app.ActivityManager$RecentTaskInfo@41de32a8, android.app.ActivityManager$RecentTaskInfo@41de3560, android.app.ActivityManager$RecentTaskInfo@41de3808, android.app.ActivityManager$RecentTaskInfo@41de3a10]

Is there a command to get the package names from this?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use reflection to inspect this object:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim o As OperatingSystem
   Dim tasks As List = o.getRecentTasks(10, 0)
   For Each task As Object In tasks
      Dim r As Reflector
      r.Target = task
      Dim bi As Object = r.GetField("baseIntent")
      If bi <> Null Then
         r.Target = bi
         r.Target = r.RunMethod("getComponent")
         Log(r.RunMethod("getPackageName"))
      End If
   Next
End Sub
 
Upvote 0
Top