場景:ActivityA嵌套Fragment,點擊按鈕跳轉(zhuǎn)到ActivityB私植, 在B 頁面進行一些操作返回A頁面時在onActivityResult() 中刷新fragment忌栅。
private void initFragment() {
String ids = StringUtil.LongIds2str(mIds);
if (fragment != null ) {
fragment = new TopicListFragment().newInstance(ids);
getSupportFragmentManager().beginTransaction().replace(R.id.fl_container, fragment).commitAllowingStateLoss();
} else {
fragment = new TopicListFragment().newInstance(ids);
getSupportFragmentManager().beginTransaction().add(R.id.fl_container, fragment).commit();
}
}
http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html