请选择 进入手机版 | 继续访问电脑版

平方X

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 506|回复: 0

[2436]ViewPager+Fragment 重新调用 onAttach

[复制链接]

414

主题

709

帖子

3454

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3454
QQ
发表于 2017-11-30 17:02:26 | 显示全部楼层 |阅读模式
[md]
一开始以为只会调用一次,但是我们的场景是 ViewPager + FragmentAdapter  
导致实际过程中重新调用,调用过程如下
# ViewPager
android.support.v4.view.ViewPager#setCurrentItem(int)
android.support.v4.view.ViewPager#setCurrentItemInternal(int, boolean, boolean)
android.support.v4.view.ViewPager#setCurrentItemInternal(int, boolean, boolean, int)
android.support.v4.view.ViewPager#populate(int)
在这一步中处理 item
    先调用
    android.support.v4.view.PagerAdapter#startUpdate(android.view.ViewGroup)
    添加
    android.support.v4.view.ViewPager#addNewItem
    android.support.v4.view.PagerAdapter#instantiateItem(android.view.ViewGroup, int)
    移除
    android.support.v4.view.PagerAdapter#destroyItem(android.view.ViewGroup, int, java.lang.Object)
    然后调用
    android.support.v4.view.PagerAdapter#setPrimaryItem(android.view.ViewGroup, int, java.lang.Object)
    android.support.v4.view.PagerAdapter#finishUpdate(android.view.ViewGroup)

# Adapter
## android.support.v4.app.FragmentStatePagerAdapter
android.support.v4.app.FragmentStatePagerAdapter#instantiateItem
android.support.v4.app.FragmentStatePagerAdapter#destroyItem
android.support.v4.app.FragmentStatePagerAdapter#finishUpdate
    调用
    android.support.v4.app.FragmentTransaction#commitNowAllowingStateLoss

# android.support.v4.app.BackStackRecord
android.support.v4.app.BackStackRecord#commitNowAllowingStateLoss
android.support.v4.app.FragmentManagerImpl#execSingleAction
android.support.v4.app.FragmentManagerImpl#optimizeAndExecuteOps
android.support.v4.app.FragmentManagerImpl#executeOpsTogether
android.support.v4.app.FragmentTransition#startTransitions
android.support.v4.app.FragmentTransition#calculateFragments
android.support.v4.app.FragmentTransition#addToFirstInLastOut
android.support.v4.app.FragmentManagerImpl#moveToState(android.support.v4.app.Fragment, int, int, int, boolean)

# android.support.v4.app.FragmentManagerImpl
android.support.v4.app.FragmentManagerImpl#moveToState(android.support.v4.app.Fragment, int, int, int, boolean)
android.support.v4.app.Fragment#onAttach(android.content.Context)[/md]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|平方X ( 冀ICP备14018164号 )

GMT+8, 2020-6-2 04:50 , Processed in 0.132411 second(s), 21 queries .

技术支持:Powered by Discuz!X3.4  © 2001-2013 Comsenz Inc.

版权所有:Copyright © 2014-2018 平方X www.pingfangx.com All rights reserved.

快速回复 返回顶部 返回列表