10

I'm trying to make an automatic night mode for my phone using "Automate", but I can't find certain app activities.

How do I get to know what activities are executed in the foreground at the moment, so I can start it?

Andrew T.
  • 16,898
  • 10
  • 77
  • 134
Deerie
  • 101
  • 1
  • 1
  • 4

3 Answers3

9

Using apps: Current Activity and some similar apps will display the info in the form of floating texts above the screen content.

Using adb shell (from your PC):

  • dumpsys window windows | grep -E 'mCurrentFocus', or
  • dumpsys activity top (for full info meant for developers)
Andy Yan
  • 9,667
  • 17
  • 32
  • 56
2

To add to @AndyYan's answer, you can also use a terminal emulator app, if you don't have a computer but have root privileges. In this case, execute su first. Then, to dump the focused activity, the command is

dumpsys activity activities | grep mFocusedActivity

The command, if e.g. executed from Terminal Emulator, gives the following output:

  mFocusedActivity: ActivityRecord{415c7ae u0 jackpal.androidterm/.Term t96}

The command above, as Andy pointed out, merely shows the Terminal's own activity, though. In order to give yourself enough time to open the app you wish to investigate, though, you need to prepend

sleep <seconds> && 

before the actual dumpsyscommand, replacing <seconds> with the number of seconds you want the shell to wait. An example of complete command, thus, will resemble

sleep 10 && dumpsys activity activities | grep mFocusedActivity

After executing the command, open the app you wish to investigate, and keep it in foreground for the number of seconds you specified. Once the time has elapsed, the shell will report the activity's name.


I'm not affiliated to the abovementioned app.

Grimoire
  • 2,978
  • 4
  • 17
  • 31
1
Via The CLI
  1. The Command

    Per a comment on GitHub by an activity manager developer (paraphrased):

    #!/usr/bin/env sh
    adb shell dumpsys activity activities \
        | grep topResumedActivity=        \
            | awk '{ print $3 }'
    
  2. Example Output

    app.revanced.android.youtube/com.google.android.apps.youtube.app.watchwhile.InternalMainActivity

Via A GUI

As this Software Recommendations SE answer explains:

As this GitHub comment from the developer of an activity manager application for AOSP 14 explains, this should be available in all versions > 3.1.7:

Implemented in 45ff4f8.

However, I've yet to see it. Perhaps, compile from HEAD.