16

I'm looking a solution to determine which fragments are currently visible from dumpsys

I can get info about activities

$ adb shell dumpsys activity | grep -i run

Is there any solution for fragments or how do you determine visible fragments from dumpsys?

Orhan Obut
  • 8,288
  • 5
  • 29
  • 41

3 Answers3

30

Check documentation with adb shell dumpsys activity -h. You can provide a <COMP_SPEC> parameter, adb shell dumpsys activity <COMP_SPEC>. When you give the <COMP_SPEC> parameter, you get more information on the specific component, including the visible fragments and views.

Example when Android device settings are displayed:

$ adb shell dumpsys activity com.android.settings

On my device, the command output contains:

...
Active Fragments in 13c3a270:
  #0: DashboardSummary{186a79e9 #0 id=0x7f0e017b}
    mFragmentId=#7f0e017b mContainerId=#7f0e017b mTag=null
    mState=5 mIndex=0 mWho=android:fragment:0 mBackStackNesting=0
    mAdded=true mRemoving=false mResumed=true mFromLayout=false mInLayout=false
    mHidden=false mDetached=false mMenuVisible=true mHasMenu=false
    mRetainInstance=false mRetaining=false mUserVisibleHint=true
    mFragmentManager=FragmentManager{13c3a270 in Settings{ef6d7d6}}
    mActivity=com.android.settings.Settings@ef6d7d6
    mContainer=android.widget.FrameLayout{9b1166e V.E..... ........ 0,0-768,1022 #7f0e017b app:id/main_content}
    mView=android.widget.ScrollView{1c50410f VFED.V.. ........ 0,0-768,1022 #7f0e005a app:id/dashboard}
    Child FragmentManager{2298759c in DashboardSummary{186a79e9}}:
      FragmentManager misc state:
        mActivity=com.android.settings.Settings@ef6d7d6
        mContainer=android.app.Fragment$1@167cba5
        mParent=DashboardSummary{186a79e9 #0 id=0x7f0e017b}
        mCurState=5 mStateSaved=false mDestroyed=false
...
Juuso Ohtonen
  • 6,643
  • 7
  • 54
  • 89
  • Is it possible to get visible fragments that are the content of a soft keyboard? Like to open an app in which there is an input field, click it and get a list or fragments for each button/letter, suggestion field, etc? – Nicofisi Jul 06 '17 at 23:17
  • 1
    @Nicofisi You can obtain the visibility of soft keyboard with `adb shell dumpsys window InputMethod | grep "mHasSurface"` https://stackoverflow.com/a/25781978/1097104 However, with a brief testing, I could not obtain the contents of the keyboard (I diffed the dumps of keyboard visible and invisible). – Juuso Ohtonen Jul 07 '17 at 03:55
  • 1
    @Nicofisi Please post a new question on your issue to get more visibility (and perhaps a real answer). – Juuso Ohtonen Jul 12 '17 at 03:27
  • Thanks, it's very helpful! Is there anything in Android Studio to help visualize the output? – vir us Sep 19 '17 at 13:02
  • @vir us maybe this? http://discuss.appium.io/t/uiautomatorviewer-is-now-replaced-with-monitor-starting-with-android-studio-2-3/15231 – Juuso Ohtonen Sep 19 '17 at 13:08
8

This will show a live view of your activities and fragments:

watch -n 1 "adb shell dumpsys activity top | grep -E 'Fragment|Activity' | head -60"
elliptic1
  • 1,355
  • 1
  • 16
  • 20
0
adb shell dumpsys activity $package_name_of_foreground_app | grep Fragment

way to get package_name_of_foreground_app may be different, for me is:

adb shell dumpsys activity recents | grep 'Recent #0' | cut -d= -f6 | sed 's| .*||' | cut -d '/' -f1 | cut -d: -f2
devzyc
  • 29
  • 1
  • 3