51
51

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

FragmentのpopBackStackまとめ

Last updated at Posted at 2015-03-31
一つ前の状態に戻す

popBackStack()

getFragmentManager().popBackStack();
指定したIDの状態に戻す

getBackStackEntryAt(int index)
popBackStack(int id, int flags)

FragmentManager fm = getFragmentManager();
BackStackEntry entry = fm.getBackStackEntryAt(0);
int id = entry.getId();
fm.popBackStack(id, 0)

※Stack に何もない場合は getBackStackEntry(0) が null になる

指定したIDの状態の一つ前に戻す
指定したタグの状態に戻す

popBackStack(String name, int flags)

// 事前に下記のような操作を行う
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace({id}, {Fragment});
ft.addToBackStack("TAG");
ft.commit();
// TAG まで戻る
FragmentManager fm = getFragmentManager();
fm.popBackStack("TAG", 0)
指定したタグの状態の一つ前に戻す
// 事前に下記のような操作を行う
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace({id}, {Fragment});
ft.addToBackStack("TAG");
ft.commit();
// TAG の前まで戻る
FragmentManager fm = getFragmentManager();
fm.popBackStack("TAG", FragmentManager.POP_BACK_STACK_INCLUSIVE)

下記のメソッドはそれぞれ上記メソッドと同じ内容が同期的に行われる

FragmentManager.popBackStackImmediate()

FragmentManager.popBackStackImmediate(int id, int flags)

FragmentManager.popBackStackImmediate(String name, int flags)

51
51
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
51
51

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?