如果您正在使用活动,则从活动A调用前活动B.如果按下后退按钮,则返回到具有实际视图的活动A.没关系。但是在片段中,ex片段B被片段A替换。当按下后退按钮时,它返回到片段A,但是某些视图缺失或空白。如何克服这个问题?
提前致谢
代码片段事务
public void onMenuItemSelected(int n) {
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
if( n == 0 ){
DeviceControl devcontrolFragment = new DeviceControl();
transaction.replace(R.id.contentFragment, devcontrolFragment);
transaction.addToBackStack(null);
transaction.commit();
}
else if( n == 1 ){
EventLog eventlogFragment = new EventLog();
transaction.replace(R.id.contentFragment, eventlogFragment);
transaction.addToBackStack(null);
transaction.commit();
}
else if( n == 5 ){
Intent intent = new Intent();
intent.setClass(this, HomesList.class);
startActivity(intent);
}
}
backstack代码
public void onBackBtn( View v ){
if( getFragmentManager().getBackStackEntryCount() > 1){
getFragmentManager().popBackStack();
}
}