Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 663
Orhan Obut Avatar asked Jun 26 '14 11:06

Orhan Obut


People also ask

How do you find the current visible fragment?

Fragment visibleFragment=getCurrentFragment(); calling this function you can get current visible fragment.

What is Dumpsys command?

dumpsys is a tool that runs on Android devices and provides information about system services. You can call dumpsys from the command line using the Android Debug Bridge (ADB) to get diagnostic output for all system services running on a connected device.

What is FragmentManager in Android?

FragmentManager is the class responsible for performing actions on your app's fragments, such as adding, removing, or replacing them, and adding them to the back stack.


1 Answers

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
...
like image 147
Juuso Ohtonen Avatar answered Sep 21 '22 01:09

Juuso Ohtonen