0

SecondActivity唯一的布局很简单,在ContentView它的onCreate()方法中设置:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
}

而且activity_second.xml是:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SecondActivity" />

但是当我dumpsys用来转储最重要的活动时,它会Fragment在输出中列出一个未知数(“ReportFragment”):

$ adb shell dumpsys activity top
TASK xxx.lifecycleapplication id=4
  ACTIVITY xxx.lifecycleapplication/.SecondActivity 538274ac pid=1519
    Local Activity 5368915c State:
      mResumed=true mStopped=false mFinished=false
      mLoadersStarted=true
      mChangingConfigurations=false
      mCurrentConfig={1.0 310mcc270mnc en_US sw384dp w384dp h567dp nrml port finger qwerty/v/v dpad/v s.5}
    Active Fragments in 536891f0:
      #0: ReportFragment{5369f99c #0 androidx.lifecycle.LifecycleDispatcher.report_fragment_tag}
        mFragmentId=#0 mContainerId=#0 mTag=androidx.lifecycle.LifecycleDispatcher.report_fragment_tag
        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{536891f0 in SecondActivity{5368915c}}
        mActivity=xxx.lifecycleapplication.SecondActivity@5368915c
    Added Fragments:
      #0: ReportFragment{5369f99c #0 androidx.lifecycle.LifecycleDispatcher.report_fragment_tag}
    FragmentManager misc state:
      mCurState=5 mStateSaved=false mDestroyed=false
    Local FragmentActivity 5368915c State:
      mCreated=true mResumed=true mStopped=false    FragmentManager misc state:
      mHost=androidx.fragment.app.FragmentActivity$HostCallbacks@5368b814
      mContainer=androidx.fragment.app.FragmentActivity$HostCallbacks@5368b814
      mCurState=4 mStateSaved=false mStopped=false mDestroyed=false

为什么输出显示ReportFragment在“Active Fragments”和“Added Fragments”中,而我没有使用任何Fragment

4

1 回答 1

0

这条线是线索:

mTag=androidx.lifecycle.LifecycleDispatcher.report_fragment_tag

ReportFragment是一个实现细节lifecycle-processProcessLifecycleOwner用于跟踪您的应用程序是否有任何已启动的活动。在 API 29 之前,它使用框架 Fragment 来跟踪所有活动(无论它们是常规子类AppCompatActivity还是常规Activity子类)。

于 2020-03-26T04:14:17.427 回答