1、getFragmentManager 和 getChildFragmentManager 导致空指针
2、commitNowAllowingStateLoss 和commit
3、onHiddenChanged \onDestroyView \onDestroy 等生命周期中做反注册
4、Fragment的通过状态的变迁维护生命周期,比较有特点
http://www.jianshu.com/p/d9143a92ad94 Fragment踩过的坑
https://juejin.im/entry/5713a3ea2e958a005ce7977f
replace()、hide()、show()
需要我们注意的是:Fragment展示也有两种方式:
一种是replace,另一种就是hide、show,那么这两种方式有什么区别呢?
replace显示的话会调用Fragment的生命周期,也就是说它会销毁视图,重新加载,这种方式的话如果你的Fragment里面有大量的数据或者说很多视图结构的话不推荐使用这种,会增大你的内存消耗。
hide和show就是显示隐藏fragment了,最终结果也就是V’isibliity设置VISIBLE和GONE了。
fragment界面重叠问题的终极解决方法
原因:为什么会出现界面重叠呢?因为每当我们离开Activity的时候,切换到别的APP的时候,当内存不够用,Fragment所在Activity被销毁,会调用onSaveInstanceState()方法,Fragment都会被保存起来,当我再次回到这个app的时候,通过onCreate中的参数savedInstanceState恢复了之前的fragment,就导致了界面重叠。
内存泄漏
内存抖动
12-07 07:01:53.748 22716-24158/android.process.media D/dalvikvm: GC_FOR_ALLOC freed 465K, 16% free 3190K/3780K, paused 4ms, total 5ms
12-07 07:01:53.792 7579-24156/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 4684K, 19% free 49954K/61620K, paused 88ms, total 88ms
12-07 07:01:54.156 7579-24157/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1857K, 18% free 51087K/61620K, paused 112ms, total 112ms
12-07 07:01:54.484 7579-24156/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1956K, 18% free 50787K/61620K, paused 145ms, total 146ms
12-07 07:01:54.796 7579-24155/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1654K, 18% free 51087K/61620K, paused 118ms, total 118ms
12-07 07:01:55.056 7579-24156/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1632K, 18% free 51087K/61620K, paused 87ms, total 87ms
12-07 07:01:55.284 7579-24155/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1648K, 18% free 51088K/61620K, paused 100ms, total 100ms
12-07 07:01:55.560 7579-24155/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1621K, 18% free 51087K/61620K, paused 115ms, total 115ms
12-07 07:01:55.824 7579-24155/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1968K, 18% free 50788K/61620K, paused 95ms, total 95ms
12-07 07:01:56.064 7579-24154/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1632K, 18% free 51088K/61620K, paused 115ms, total 115ms
12-07 07:01:56.368 7579-24156/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1644K, 18% free 51091K/61620K, paused 114ms, total 114ms
12-07 07:01:56.624 7579-24157/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1645K, 18% free 51090K/61620K, paused 106ms, total 106ms
12-07 07:01:57.688 7579-24154/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1631K, 18% free 51090K/61620K, paused 101ms, total 101ms
12-07 07:01:58.540 7579-24154/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1676K, 18% free 51090K/61620K, paused 98ms, total 98ms
12-07 07:01:59.084 7579-24157/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1619K, 18% free 51088K/61620K, paused 165ms, total 165ms
12-07 07:01:59.680 7579-24154/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1633K, 18% free 51088K/61620K, paused 99ms, total 103ms
12-07 07:02:00.464 7579-24157/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1633K, 18% free 51088K/61620K, paused 107ms, total 107ms
12-07 07:02:01.292 7579-24157/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1651K, 18% free 51088K/61620K, paused 82ms, total 82ms
12-07 07:02:02.264 7579-24157/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1730K, 18% free 51089K/61620K, paused 80ms, total 80ms
12-07 07:02:03.160 7579-24156/com.sankuai.erp.cashier.debug D/dalvikvm: GC_FOR_ALLOC freed 1635K, 18% free 51088K/61620K, paused 89ms, total 89ms
12-07 07:02:03.436 564-605/system_process D/dalvikvm: GC_FOR_ALLOC freed 1843K, 67% free 10159K/30612K, paused 36ms, total 36ms
12-07 07:03:06.628 622-622/com.android.systemui D/dalvikvm: GC_FOR_ALLOC freed 857K, 65% free 8070K/22976K, paused 8ms, total 8ms