2017-08-26 38 views
-2

我有2个片段。片段1在应用程序的开始处加载。使用抽屉导航和片段管理器,我在其上添加片段2。Android碎片 - 生命周期与交易执行

  1. 此时片段1的状态是什么?
  2. 当按Fragment 2上的返回按钮并显示片段1时,如何刷新片段1?

回答

1

使用此在您的活动....

@Override 
    public void onBackPressed() { 
     Fragment f = getSupportFragmentManager().findFragmentById(R.id.maincontainer); 
     if (f instanceof FirstFragment) { 
      // do operations 

     } else if (f instanceof SecondFragment) { 
      // do operations 

     }else { 
      super.onBackPressed(); 
     } 

    } 
+0

你能提供一个小例子。请。 – Payal

+0

发布有关问题的两个片段。 – sushildlh