2014-01-15 101 views
0

我正在尝试导航回到另一个活动的活动片段。我已经设置从其他活动导航回到活动的片段

getActionBar().setDisplayHomeAsUpEnabled(true); 

但每当我使用的应用程序图标后面总是带我到活动的第一个片段,而不是从另一个活动推出的片段。我怎样才能做到这一点。我想我可能必须执行

getSupportFragmentManager().popBackStack(); 

我该怎么办?

回答

0

尝试添加您想要手动返回到堆栈的片段。

FragmentTransaction transaction = getFragmentManager().beginTransaction(); 
YourFragmentName myFragment = new YourFragmentName(); 
transaction.replace(R.id.fragment_container, myFragment); 

//if you with to add it to backStack, do this, otherwise skip the line below 
transaction.addToBackStack(null); 
transaction.commit(); 

希望这会有所帮助。

0

希望不晚的答案可能帮助别人后 你这样做


FragmentManager fragmentManager = getFragmentManager();
fragmentManager。 beginTransaction()。替换(R.id。(你当前的acticity的布局i),新的(你的活动的名称)).commit();