Fragment push and pop

  When jumping to a fragment:

  holder is your Activity that inherits FragmentActivity

 
public void goFragment (Fragment targetFragment, Bundle bundle) {
  FragmentTransaction transaction = holder.fragmentManager.beginTransaction();
  if (bundle != null) {
       targetFragment.setArguments(bundle);
     }
transaction.replace(R.id.re_content, targetFragment, targetFragment.getClass().getName());
		transaction.addToBackStack(targetFragment.getClass().getName());
		transaction.commit();
	}


  When returning to the previous page:

 
public void backFragment (Fragment sourceFragment) {
    if (sourceFragment != null) {
			holder.fragmentManager.beginTransaction().hide(sourceFragment);
		}
		holder.fragmentManager.popBackStack();
	}


   When jumping to the next page and cannot go back
	public void goFragmentNoBackStack (Fragment targetFragment, Bundle bundle) {
		holder.fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
		FragmentTransaction transaction = holder.fragmentManager.beginTransaction();
		if (bundle != null) {
			targetFragment.setArguments(bundle);
		}
		transaction.replace(R.id.re_content, targetFragment);
		transaction.commit();
	}


  The above method is not suitable for Alipay payment, especially after obtaining the response of Alipay:
  for the Alipay situation, it is recommended to use a new Activity to process, through startActivityForResult, so that no exception will be thrown

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327077190&siteId=291194637