当前位置: 首页 > news >正文

网络推广可做哪些方面石家庄百度seo排名

网络推广可做哪些方面,石家庄百度seo排名,北京好的网站设计公司,公司入口网站app我们知道Fragment的生命周期依附于相应Activity的生命周期,如果activity A调用了onPause,则A里面的fragment也会相应收到onPause回调,这里以support27.1.1版本的源码来说明Fragment生命周期onPause的事情。 当activity执行onPause时&#xff…

        我们知道Fragment的生命周期依附于相应Activity的生命周期,如果activity A调用了onPause,则A里面的fragment也会相应收到onPause回调,这里以support27.1.1版本的源码来说明Fragment生命周期onPause的事情。

        当activity执行onPause时,进入如下的代码:

    /*** Dispatch onPause() to fragments.*/@Overrideprotected void onPause() {super.onPause();mResumed = false;if (mHandler.hasMessages(MSG_RESUME_PENDING)) {mHandler.removeMessages(MSG_RESUME_PENDING);onResumeFragments();}mFragments.dispatchPause();//关注这里}

        mFragments.dispatchPause()这里进入到Fragment的生命周期分发流程中,mFragments其实是一个FragmentController对象,dispatchPause相应代码如下:

    /*** Moves all Fragments managed by the controller's FragmentManager* into the pause state.* <p>Call when Fragments should be paused.** @see Fragment#onPause()*/public void dispatchPause() {mHost.mFragmentManager.dispatchPause();}

        这里也是简单的调用转发,进入到FragmentManager里面的dispatchPause方法,如下:

public void dispatchCreate() {mStateSaved = false;mStopped = false;dispatchStateChange(Fragment.CREATED);}public void dispatchActivityCreated() {mStateSaved = false;mStopped = false;dispatchStateChange(Fragment.ACTIVITY_CREATED);}public void dispatchStart() {mStateSaved = false;mStopped = false;dispatchStateChange(Fragment.STARTED);}public void dispatchResume() {mStateSaved = false;mStopped = false;dispatchStateChange(Fragment.RESUMED);}public void dispatchPause() {dispatchStateChange(Fragment.STARTED);}public void dispatchStop() {mStopped = true;dispatchStateChange(Fragment.STOPPED);}public void dispatchReallyStop() {dispatchStateChange(Fragment.ACTIVITY_CREATED);}public void dispatchDestroyView() {dispatchStateChange(Fragment.CREATED);}public void dispatchDestroy() {mDestroyed = true;execPendingActions();dispatchStateChange(Fragment.INITIALIZING);mHost = null;mContainer = null;mParent = null;}private void dispatchStateChange(int nextState) {try {mExecutingActions = true;moveToState(nextState, false);} finally {mExecutingActions = false;}execPendingActions();}

        这里有一堆的生命周期事件分发入口,说明Activity的相应生命周期事件都会分发到这里对应的方法;当前的onPause会进入dispatchPause方法,然后调用dispatchStateChange方法,注意调用参数为Fragment.STARTED(值为4),这里看看Fragment的几个状态定义如下:

    static final int INITIALIZING = 0;     // Not yet created.static final int CREATED = 1;          // Created.static final int ACTIVITY_CREATED = 2; // The activity has finished its creation.static final int STOPPED = 3;          // Fully created, not started.static final int STARTED = 4;          // Created and started, not resumed.static final int RESUMED = 5;          // Created started and resumed.int mState = INITIALIZING;

        接着进入moveToState方法,重点来了,即将进入Fragment的状态转换了,传递给moveToState的参数nextState为Fragment.STARTED(值为4),always为false,相应代码如下:

    /*** Changes the state of the fragment manager to {@code newState}. If the fragment manager* changes state or {@code always} is {@code true}, any fragments within it have their* states updated as well.** @param newState The new state for the fragment manager* @param always If {@code true}, all fragments update their state, even*               if {@code newState} matches the current fragment manager's state.*/void moveToState(int newState, boolean always) {if (mHost == null && newState != Fragment.INITIALIZING) {throw new IllegalStateException("No activity");}if (!always && newState == mCurState) {return;}mCurState = newState;//1关注这里if (mActive != null) {// Must add them in the proper order. mActive fragments may be out of orderfinal int numAdded = mAdded.size();for (int i = 0; i < numAdded; i++) {Fragment f = mAdded.get(i);moveFragmentToExpectedState(f);//2关注这里}// Now iterate through all active fragments. These will include those that are removed// and detached.final int numActive = mActive.size();for (int i = 0; i < numActive; i++) {Fragment f = mActive.valueAt(i);if (f != null && (f.mRemoving || f.mDetached) && !f.mIsNewlyAdded) {moveFragmentToExpectedState(f);}}startPendingDeferredFragments();if (mNeedMenuInvalidate && mHost != null && mCurState == Fragment.RESUMED) {mHost.onSupportInvalidateOptionsMenu();mNeedMenuInvalidate = false;}}}

        moveToState中关注两点,首先是将状态newState保存到mCurState(为STARTED,4)中,其次遍历集合mAdded并调用moveFragmentToExpectedState改变相应fragment的生命周期状态。

mAdded:保存当前activity中已经添加的fragment实例。

        moveFragmentToExpectedState代码如下:

    /*** Moves a fragment to its expected final state or the fragment manager's state, depending* on whether the fragment manager's state is raised properly.** @param f The fragment to change.*/void moveFragmentToExpectedState(Fragment f) {if (f == null) {return;}int nextState = mCurState;if (f.mRemoving) {if (f.isInBackStack()) {nextState = Math.min(nextState, Fragment.CREATED);} else {nextState = Math.min(nextState, Fragment.INITIALIZING);}}//状态转换moveToState(f, nextState, f.getNextTransition(), f.getNextTransitionStyle(), false);if (f.mView != null) {// Move the view if it is out of orderFragment underFragment = findFragmentUnder(f);if (underFragment != null) {final View underView = underFragment.mView;// make sure this fragment is in the right order.final ViewGroup container = f.mContainer;int underIndex = container.indexOfChild(underView);int viewIndex = container.indexOfChild(f.mView);if (viewIndex < underIndex) {container.removeViewAt(viewIndex);container.addView(f.mView, underIndex);}}if (f.mIsNewlyAdded && f.mContainer != null) {// Make it visible and run the animationsif (f.mPostponedAlpha > 0f) {f.mView.setAlpha(f.mPostponedAlpha);}f.mPostponedAlpha = 0f;f.mIsNewlyAdded = false;// run animations:AnimationOrAnimator anim = loadAnimation(f, f.getNextTransition(), true,f.getNextTransitionStyle());if (anim != null) {setHWLayerAnimListenerIfAlpha(f.mView, anim);if (anim.animation != null) {f.mView.startAnimation(anim.animation);} else {anim.animator.setTarget(f.mView);anim.animator.start();}}}}if (f.mHiddenChanged) {completeShowHideFragment(f);}}

        该方法主要调用moveToState执行Fragment状态转换,这里将执行真正的生命周期方法,代码如下:

    @SuppressWarnings("ReferenceEquality")void moveToState(Fragment f, int newState, int transit, int transitionStyle,boolean keepActive) {// Fragments that are not currently added will sit in the onCreate() state.if ((!f.mAdded || f.mDetached) && newState > Fragment.CREATED) {newState = Fragment.CREATED;}if (f.mRemoving && newState > f.mState) {if (f.mState == Fragment.INITIALIZING && f.isInBackStack()) {// Allow the fragment to be created so that it can be saved later.newState = Fragment.CREATED;} else {// While removing a fragment, we can't change it to a higher state.newState = f.mState;}}// Defer start if requested; don't allow it to move to STARTED or higher// if it's not already started.if (f.mDeferStart && f.mState < Fragment.STARTED && newState > Fragment.STOPPED) {newState = Fragment.STOPPED;}if (f.mState <= newState) {// For fragments that are created from a layout, when restoring from// state we don't want to allow them to be created until they are// being reloaded from the layout.//该分支表示生命周期转换 create -> start -> resume} else if (f.mState > newState) {//该分支表示生命周期转换 pause -> stop -> destoryView -> destory -> detachswitch (f.mState) {case Fragment.RESUMED:if (newState < Fragment.RESUMED) {if (DEBUG) Log.v(TAG, "movefrom RESUMED: " + f);f.performPause();dispatchOnFragmentPaused(f, false);}// fall throughcase Fragment.STARTED:if (newState < Fragment.STARTED) {if (DEBUG) Log.v(TAG, "movefrom STARTED: " + f);f.performStop();dispatchOnFragmentStopped(f, false);}// fall throughcase Fragment.STOPPED:if (newState < Fragment.STOPPED) {if (DEBUG) Log.v(TAG, "movefrom STOPPED: " + f);f.performReallyStop();}// fall throughcase Fragment.ACTIVITY_CREATED:if (newState < Fragment.ACTIVITY_CREATED) {if (DEBUG) Log.v(TAG, "movefrom ACTIVITY_CREATED: " + f);if (f.mView != null) {// Need to save the current view state if not// done already.if (mHost.onShouldSaveFragmentState(f) && f.mSavedViewState == null) {saveFragmentViewState(f);}}f.performDestroyView();dispatchOnFragmentViewDestroyed(f, false);if (f.mView != null && f.mContainer != null) {// Stop any current animations:f.mContainer.endViewTransition(f.mView);f.mView.clearAnimation();AnimationOrAnimator anim = null;if (mCurState > Fragment.INITIALIZING && !mDestroyed&& f.mView.getVisibility() == View.VISIBLE&& f.mPostponedAlpha >= 0) {anim = loadAnimation(f, transit, false,transitionStyle);}f.mPostponedAlpha = 0;if (anim != null) {animateRemoveFragment(f, anim, newState);}f.mContainer.removeView(f.mView);}f.mContainer = null;f.mView = null;f.mInnerView = null;f.mInLayout = false;}// fall throughcase Fragment.CREATED:if (newState < Fragment.CREATED) {if (mDestroyed) {// The fragment's containing activity is// being destroyed, but this fragment is// currently animating away.  Stop the// animation right now -- it is not needed,// and we can't wait any more on destroying// the fragment.if (f.getAnimatingAway() != null) {View v = f.getAnimatingAway();f.setAnimatingAway(null);v.clearAnimation();} else if (f.getAnimator() != null) {Animator animator = f.getAnimator();f.setAnimator(null);animator.cancel();}}if (f.getAnimatingAway() != null || f.getAnimator() != null) {// We are waiting for the fragment's view to finish// animating away.  Just make a note of the state// the fragment now should move to once the animation// is done.f.setStateAfterAnimating(newState);newState = Fragment.CREATED;} else {if (DEBUG) Log.v(TAG, "movefrom CREATED: " + f);if (!f.mRetaining) {f.performDestroy();dispatchOnFragmentDestroyed(f, false);} else {f.mState = Fragment.INITIALIZING;}f.performDetach();dispatchOnFragmentDetached(f, false);if (!keepActive) {if (!f.mRetaining) {makeInactive(f);} else {f.mHost = null;f.mParentFragment = null;f.mFragmentManager = null;}}}}}}if (f.mState != newState) {Log.w(TAG, "moveToState: Fragment state for " + f + " not updated inline; "+ "expected state " + newState + " found " + f.mState);f.mState = newState;}}

        moveToState包含两大分支逻辑,分别是创建与销毁,由于我们这里分析的是onPause,所以创建的分支省略了,这里newState值为Fragment.STARTED,f.mSate为Fragment.RESUMED,因此进入到Fragment.RESUMED对应的销毁分支,即执行如下代码:

                case Fragment.RESUMED:if (newState < Fragment.RESUMED) {if (DEBUG) Log.v(TAG, "movefrom RESUMED: " + f);f.performPause();dispatchOnFragmentPaused(f, false);}

        由于newState为Fragment.STARTED,其值为4小于Fragment.RESUMED(5),因此调用f.performPause,代码如下:

void performPause() {mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE);if (mChildFragmentManager != null) {mChildFragmentManager.dispatchPause();}mState = STARTED;mCalled = false;onPause();if (!mCalled) {throw new SuperNotCalledException("Fragment " + this+ " did not call through to super.onPause()");}}

        这里首先处理了生命周期变化handleLifecycleEvent,然后如果当前fragment还有子fragment的话,子fragment的生命周期会通过mChildFragmentManager.dispatchPause()来分发,这里还将当前fragment的mState变量赋值为STARTED(4),最后调用生命周期方法onPause,到这里算是走完了onPause的生命周期流程,为了逻辑的完整性,我们继续分析。

        上一步继续调用dispatchOnFragmentPaused方法,代码如下:

void dispatchOnFragmentPaused(Fragment f, boolean onlyRecursive) {if (mParent != null) {FragmentManager parentManager = mParent.getFragmentManager();if (parentManager instanceof FragmentManagerImpl) {((FragmentManagerImpl) parentManager).dispatchOnFragmentPaused(f, true);}}for (Pair<FragmentLifecycleCallbacks, Boolean> p : mLifecycleCallbacks) {if (!onlyRecursive || p.second) {p.first.onFragmentPaused(this, f);}}}

        首先判断有没有父fragment,有的话同样进行生命周期分发,其次遍历mLifecycleCallbacks并进行生命周期分发,这里的mLifecycleCallbacks其实是我们通过activity的FragmentManager调用registerFragmentLifecycleCallbacks方法注册的生命周期回调函数。

        不难看出,onPause对应的Fragment.RESUMED分支,其实只是处理生命周期相关的回调而已。

onPause分支总结:

1 处理mLifecycleRegistry中的回调。

2 通过mChildFragmentManager.dispatchPause()分发其子fragment的生命周期回调。

3 调用onPause执行自己的生命周期方法(同时mState = STARTED)。

4 如果有父framnet,则分发父frament的生命周期回调。

5 执行保存在mLifecycleCallbacks中的生命周期回调(比如LeakCanary的内存泄漏判断就是此时触发的)。

         onPause执行完成,注意到moveToState中的分支都不带break,因此会继续执行到下一分支,代码如下:

                case Fragment.RESUMED:if (newState < Fragment.RESUMED) {if (DEBUG) Log.v(TAG, "movefrom RESUMED: " + f);f.performPause();dispatchOnFragmentPaused(f, false);}// fall throughcase Fragment.STARTED://执行到这里if (newState < Fragment.STARTED) {if (DEBUG) Log.v(TAG, "movefrom STARTED: " + f);f.performStop();dispatchOnFragmentStopped(f, false);}// fall throughcase Fragment.STOPPED:if (newState < Fragment.STOPPED) {if (DEBUG) Log.v(TAG, "movefrom STOPPED: " + f);f.performReallyStop();}

        穿透到Fragment.STARTED这里,但是注意这里的代码执行时有条件的,此时newState=Fragment.STARTED,条件不满足因此不会继续执行分支的代码,之后的分支也不满足条件,因此最后跳出整个大的switch块。

        自此Fragment的onPause生命周期切换完成。

执行完onPause之后,Fragment的生命周期状态mState为Fragment.STARTED。


文章转载自:
http://cathodal.c7625.cn
http://neeze.c7625.cn
http://behoove.c7625.cn
http://tundra.c7625.cn
http://cyanoacrylate.c7625.cn
http://damply.c7625.cn
http://lucarne.c7625.cn
http://bracken.c7625.cn
http://carlsruhe.c7625.cn
http://retractable.c7625.cn
http://transferase.c7625.cn
http://leukemogenesis.c7625.cn
http://oceanographic.c7625.cn
http://dard.c7625.cn
http://adsorptive.c7625.cn
http://puce.c7625.cn
http://subtype.c7625.cn
http://saluretic.c7625.cn
http://multivalence.c7625.cn
http://oppressor.c7625.cn
http://swashbuckling.c7625.cn
http://frump.c7625.cn
http://curtate.c7625.cn
http://llewellyn.c7625.cn
http://mahzor.c7625.cn
http://schlemiel.c7625.cn
http://marmora.c7625.cn
http://distensile.c7625.cn
http://arbutus.c7625.cn
http://pygmean.c7625.cn
http://fortaleza.c7625.cn
http://japanning.c7625.cn
http://leukopenia.c7625.cn
http://bug.c7625.cn
http://gurgle.c7625.cn
http://cytophysiology.c7625.cn
http://lustrously.c7625.cn
http://zenana.c7625.cn
http://acoelomate.c7625.cn
http://embryonal.c7625.cn
http://yoick.c7625.cn
http://ephebeion.c7625.cn
http://arachnoid.c7625.cn
http://sphere.c7625.cn
http://intermesh.c7625.cn
http://vortices.c7625.cn
http://stamper.c7625.cn
http://sybaris.c7625.cn
http://ebullism.c7625.cn
http://hilch.c7625.cn
http://speciate.c7625.cn
http://overcertify.c7625.cn
http://phagomania.c7625.cn
http://rigged.c7625.cn
http://houndfish.c7625.cn
http://saponine.c7625.cn
http://skipjack.c7625.cn
http://mutably.c7625.cn
http://shipfitter.c7625.cn
http://fivefold.c7625.cn
http://adynamic.c7625.cn
http://galactosamine.c7625.cn
http://buttermilk.c7625.cn
http://remoteness.c7625.cn
http://placoderm.c7625.cn
http://thimerosal.c7625.cn
http://connate.c7625.cn
http://spitz.c7625.cn
http://mudstone.c7625.cn
http://kamerad.c7625.cn
http://pistareen.c7625.cn
http://alecithal.c7625.cn
http://cysticerci.c7625.cn
http://pinna.c7625.cn
http://ipm.c7625.cn
http://vogue.c7625.cn
http://palsa.c7625.cn
http://fundamental.c7625.cn
http://gabled.c7625.cn
http://febrific.c7625.cn
http://intermittent.c7625.cn
http://filaria.c7625.cn
http://cradling.c7625.cn
http://edgebone.c7625.cn
http://cycas.c7625.cn
http://ming.c7625.cn
http://submerse.c7625.cn
http://hogarthian.c7625.cn
http://pentahedron.c7625.cn
http://compounding.c7625.cn
http://at.c7625.cn
http://afrikaans.c7625.cn
http://domiciliate.c7625.cn
http://hereditament.c7625.cn
http://molality.c7625.cn
http://uneventful.c7625.cn
http://mage.c7625.cn
http://hassle.c7625.cn
http://legumen.c7625.cn
http://clear.c7625.cn
http://www.zhongyajixie.com/news/99470.html

相关文章:

  • 国产一级a做爰片免费网站网站seo推广优化教程
  • 北京网站开发公司谷歌google地图
  • seo对于电子商务网站推广的作用企业网络搭建方案
  • 浏阳网站建设卷云网络经典营销案例
  • 做宣传网站买什么云服务器请输入搜索关键词
  • 赢卡购网站建设2023第三波疫情已经到来了
  • 衡阳seo网站推广市场调研方法有哪几种
  • 成都网站建设 平易云智慧软文发布系统
  • 4k视频素材网站交换友链要注意什么
  • 周口建设委员会网站信息平台网站推广哪个好
  • 网站建设的语言百度纯净版首页入口
  • 哪种语言做网站最合适八爪鱼磁力搜索引擎
  • 九江市区网络推广优化是干啥的
  • wordpress做api接口seo整站优化费用
  • 可靠的微商城网站建设北京搜索引擎推广公司
  • 网站定位是什么济南网站推广优化
  • 乌鲁木齐做网站微信指数官网
  • wordpress 图片分享主题网络搜索优化
  • 赣州网站建设 赣州网页设计友点企业网站管理系统
  • 做视频特效的网站重庆seo推广
  • 下载什么网站做吃的百度一下官网搜索引擎
  • 学校门户网站每日关键词搜索排行
  • 贵州省建设厅公示网站产品宣传方式有哪些
  • 研磨 东莞网站建设2022年搜索引擎优化指南
  • 公司网站备案怎么办理淘宝店铺转让价格表
  • 网站建设深百度搜索资源平台token
  • 三丰云做网站步骤凤凰军事新闻最新消息
  • 网站建设和咨询服务合同东莞网站推广的公司
  • 阿里巴巴网站威海哪里做十大广告联盟
  • 网站空间一定要买吗网站建设推广服务