Android Question Read all acvivity title with OS.Library.

tc.goethe

Member
Licensed User
Longtime User
I want to program a service that reads out the title of an active activity. I just can not get past. I have tried the OS.Library, but I come to a conclusion. Can anyone help me? Please ....

The aim should be that at a very specific window my app comes to the foreground.
(sorry translate with google)

B4X:
Dim OS As OperatingSystem     
Dim Tasks As List     
Tasks = OS.getRunningTasks(1000)
If Tasks.Size > 0 Then
          For i = 0 To Tasks.Size - 1
              Dim r As Reflector
              r.Target = Tasks.Get(i)
              Log(r.GetField("topActivity"))
              Log(r.GetField("baseActivity"))
  Next    
End If
 
Last edited:

tc.goethe

Member
Licensed User
Longtime User
The code works. I get the names of all the activity, but not the title.
Look at the log file:

** Activity (main) Create, isFirst = true **

ComponentInfo{b4a.example/b4a.example.main}
ComponentInfo{b4a.example/b4a.example.main}

ComponentInfo{com.android.launcher/com.android.launcher2.Launcher}
ComponentInfo{com.android.launcher/com.android.launcher2.Launcher}

ComponentInfo{com.android.calculator2/com.android.calculator2.Calculator}
ComponentInfo{com.android.calculator2/com.android.calculator2.Calculator}
** Activity (main) Resume **

Do you have an idea?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can get the package name with:
B4X:
r.Target = r.GetField("topActivity")
Dim pkg As String = r.RunMethod("getPackageName")
Now with get the application label with PacakgeManager.GetApplicationLabel. The activity title can be set at runtime (Activity.Text for example). This value cannot be read. At least not with these classes.
 
Upvote 0

tc.goethe

Member
Licensed User
Longtime User
This is exactly my problem. The app changes at runtime the title. e.g. "Step1" -> "Step2" -> "Step3". My app will display additional information in "Step 3". I only read "Step 1". Do you have a solution for my problem?
 
Upvote 0

tc.goethe

Member
Licensed User
Longtime User
I thank you for your help. Then I have to try the Click event of Step 2 to read. The next challenge .....
 
Upvote 0
Top