Get info of current visible fragment(s) in android dumpsys
Asked Answered
B

3

17

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?

Beneath answered 26/6, 2014 at 11:16 Comment(0)
F
35

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
...
Footrope answered 29/1, 2015 at 6:31 Comment(5)
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?Ullman
@Ullman You can obtain the visibility of soft keyboard with adb shell dumpsys window InputMethod | grep "mHasSurface" https://mcmap.net/q/36354/-how-do-i-detect-if-software-keyboard-is-visible-on-android-device-or-not However, with a brief testing, I could not obtain the contents of the keyboard (I diffed the dumps of keyboard visible and invisible).Footrope
@Ullman Please post a new question on your issue to get more visibility (and perhaps a real answer).Footrope
Thanks, it's very helpful! Is there anything in Android Studio to help visualize the output?Traherne
@vir us maybe this? discuss.appium.io/t/…Footrope
D
11

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"
Dharna answered 8/2, 2019 at 8:41 Comment(0)
M
1
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
Moriah answered 25/4, 2021 at 9:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.