I want to create stack of multiple fragments included in linear layout. To put set of fragments to activty I use following code (R.id.content is LinearLayout):
priv开发者_C百科ate void pushToBackStack(final Fragment... fragments) {
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    for (int i = 0; i < fragments.length; i++) {
        if (i == 0) {
            ft.replace(R.id.content, fragments[i]);
        } else {
            ft.add(R.id.content, fragments[i]);
        }
    }
    ft.addToBackStack(null);
    ft.commit();
}
when i call
pushToBackStack(f1, f2);
pushToBackStack(f3, f4);
pushToBackStack(f5, f6);
there're f3,f5 and f6 visible on screen, and after pressing Back button f2,f3,f4 are displayed.
Expected behaviour is f5,f6 -> Back -> f3,f4 -> Back-> f1, f2
You can't chain calls that way, you would need to call a commit per replace or add
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论