如何通过后退按钮从一个活动导航到另一个活动fragment
?
如果你知道答案,请帮助我。我是Android的新手。
答案 0 :(得分:0)
您可以使用从Fragment切换到Activity - :
在BackPressed上实现此代码 - :
@Override
public void onBackPressed() {
super.onBackPressed();
YourFragment mapFragment = new YourFragment();
FragmentManager manager = getFragmentManager();
manager.beginTransaction().replace(R.id.landlord_apartment, mapFragment, mapFragment.getTag()).commit();
}
从片段转移到活动 - :
startActivity(new Intent(getActivity,YourActivity.Class));
从活动转移到片段 - :
YourFragment mapFragment = new YourFragment();
FragmentManager manager = getFragmentManager();
manager.beginTransaction().replace(R.id.landlord_apartment, mapFragment, mapFragment.getTag()).commit();