1.三星手機(jī)調(diào)用系統(tǒng)照相機(jī)bug
android:configChanges="keyboardHidden|orientation|screenSize"
2.解決Fragment的重復(fù)創(chuàng)建
@Override
protected void onSaveInstanceState(Bundle bundle) {
// do not call super.onSaveInstanceState()
}
3.解決Fragment的重復(fù)創(chuàng)建
在OnCreate方法對(duì)saveInstanceState進(jìn)行判斷跟狱,為空時(shí)才進(jìn)行fragment的創(chuàng)建.使用add fragment 添加時(shí)使用 add(fragment,tag)來(lái)添加.
4.FragmentStatePagerAdapter 與 FragmentStatePagerAdapter
主要區(qū)別在與對(duì)于fragment是否銷(xiāo)毀FragmentPagerAdapter:對(duì)于不再需要的fragment筐乳,選擇調(diào)用detach方法牌柄,僅銷(xiāo)毀視圖,并不會(huì)銷(xiāo)毀fragment實(shí)例拦止。FragmentStatePagerAdapter:會(huì)銷(xiāo)毀不再需要的fragment谱仪,當(dāng)當(dāng)前事務(wù)提交以后会涎,會(huì)徹底的將fragmeng從當(dāng)前Activity的FragmentManager中移除,state標(biāo)明舒帮,銷(xiāo)毀時(shí)会喝,會(huì)將其onSaveInstanceState(Bundle outState)中的bundle信息保存下來(lái),當(dāng)用戶切換回來(lái)玩郊,可以通過(guò)該bundle恢復(fù)生成新的fragment肢执,也就是說(shuō),你可以在onSaveInstanceState(Bundle outState)方法中保存一些數(shù)據(jù)译红,在onCreate中進(jìn)行恢復(fù)創(chuàng)建预茄。
如上所說(shuō),使用FragmentStatePagerAdapter當(dāng)然更省內(nèi)存侦厚,但是銷(xiāo)毀新建也是需要時(shí)間的耻陕。一般情況下拙徽,如果你是制作主頁(yè)面,就3淮蜈、4個(gè)Tab斋攀,那么可以選擇使用FragmentPagerAdapter,如果你是用于ViewPager展示數(shù)量特別多的條目時(shí)梧田,那么建議使用FragmentStatePagerAdapter
ddd
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//透明狀態(tài)欄
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
setContentView(R.layout.activity_main);
// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}