所以我在某个时候称为MainActivity的活动中进入了另一个名为OtherActionsActivity的活动,在这个活动中,我首先有3个片段 AllProductsFragment在此片段中的某个点,我打开DialogFragment并从中选择一种产品类型,然后在选择另一个片段后打开称为AddProductFragment的产品。 我的问题是,当AddProductFragment处于活动状态并单击返回按钮时,它会杀死整个活动,但正常流程是: 从OtherActionsActivity转发1:AllProductFragment-> DialogFragment-> AddProductFragment。 2-从OtherActionsActivity向后退:AddProductFragment-> AllProductFragment
OtherActionsActivity onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_other_actions);
if (getIntent().getExtras() != null) {
currentPageFragment = (Fragment) getIntent().getExtras().getSerializable(CURRENT_PAGE_ID);
}
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.other_actions_container, currentPageFragment)
.commit();
}
}
@Override
public void navigateTo(Fragment fragment, boolean addToBackstack) {
FragmentTransaction transaction =
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.other_actions_container, fragment);
if (addToBackstack) {
transaction.addToBackStack(null);
}
transaction.commit();
}
从AllProductFragment传输到DialogFragment
DialogFragment dialog = SelectChoiceFragment.getInstance(R.string.products_type_title, R.array.products_types
, false, null);
dialog.show(getFragmentManager(), "dialog");
从对话框转移到AddProductFragment
((OtherActionsActivity)getActivity())
.navigateTo(AddProductFragment.getInstance(checkedItems), false);
非常感谢。