1.三星手機調用系統(tǒng)照相機bug
android:configChanges="keyboardHidden|orientation|screenSize"
2.解決Fragment的重復創(chuàng)建
@Override
protected void onSaveInstanceState(Bundle bundle) {
// do not call super.onSaveInstanceState()
}
3.解決Fragment的重復創(chuàng)建
在OnCreate方法對saveInstanceState進行判斷,為空時才進行fragment的創(chuàng)建.使用add fragment 添加時使用 add(fragment,tag)來添加.
4.FragmentStatePagerAdapter 與 FragmentStatePagerAdapter
主要區(qū)別在與對于fragment是否銷毀FragmentPagerAdapter:對于不再需要的fragment,選擇調用detach方法,僅銷毀視圖,并不會銷毀fragment實例。FragmentStatePagerAdapter:會銷毀不再需要的fragment,當當前事務提交以后,會徹底的將fragmeng從當前Activity的FragmentManager中移除,state標明,銷毀時,會將其onSaveInstanceState(Bundle outState)中的bundle信息保存下來,當用戶切換回來,可以通過該bundle恢復生成新的fragment,也就是說,你可以在onSaveInstanceState(Bundle outState)方法中保存一些數據,在onCreate中進行恢復創(chuàng)建。
如上所說,使用FragmentStatePagerAdapter當然更省內存,但是銷毀新建也是需要時間的。一般情況下,如果你是制作主頁面,就3、4個Tab,那么可以選擇使用FragmentPagerAdapter,如果你是用于ViewPager展示數量特別多的條目時,那么建議使用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();
}
});
}