Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 1 | package android.app; |
| 2 | |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 3 | import android.annotation.AnimatorRes; |
| 4 | import android.annotation.IdRes; |
| 5 | import android.annotation.IntDef; |
| 6 | import android.annotation.Nullable; |
| 7 | import android.annotation.StringRes; |
| 8 | import android.annotation.StyleRes; |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 9 | import android.view.View; |
| 10 | |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 11 | import java.lang.annotation.Retention; |
| 12 | import java.lang.annotation.RetentionPolicy; |
| 13 | |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 14 | /** |
| 15 | * API for performing a set of Fragment operations. |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 16 | * |
| 17 | * <div class="special reference"> |
| 18 | * <h3>Developer Guides</h3> |
| 19 | * <p>For more information about using fragments, read the |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 20 | * <a href="{@docRoot}guide/components/fragments.html">Fragments</a> developer |
| 21 | * guide.</p> |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 22 | * </div> |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 23 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 24 | public abstract class FragmentTransaction { |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Calls {@link #add(int, Fragment, String)} with a 0 containerViewId. |
| 27 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 28 | public abstract FragmentTransaction add(Fragment fragment, String tag); |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 29 | |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Calls {@link #add(int, Fragment, String)} with a null tag. |
| 32 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 33 | public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment); |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 34 | |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Add a fragment to the activity state. This fragment may optionally |
| 37 | * also have its view (if {@link Fragment#onCreateView Fragment.onCreateView} |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 38 | * returns non-null) inserted into a container view of the activity. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 39 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 40 | * @param containerViewId Optional identifier of the container this fragment is |
| 41 | * to be placed in. If 0, it will not be placed in a container. |
| 42 | * @param fragment The fragment to be added. This fragment must not already |
| 43 | * be added to the activity. |
| 44 | * @param tag Optional tag name for the fragment, to later retrieve the |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 45 | * fragment with {@link FragmentManager#findFragmentByTag(String) |
| 46 | * FragmentManager.findFragmentByTag(String)}. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 47 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 48 | * @return Returns the same FragmentTransaction instance. |
| 49 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 50 | public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment, |
| 51 | String tag); |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 52 | |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Calls {@link #replace(int, Fragment, String)} with a null tag. |
| 55 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 56 | public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment); |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 57 | |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Replace an existing fragment that was added to a container. This is |
| 60 | * essentially the same as calling {@link #remove(Fragment)} for all |
| 61 | * currently added fragments that were added with the same containerViewId |
| 62 | * and then {@link #add(int, Fragment, String)} with the same arguments |
| 63 | * given here. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 64 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 65 | * @param containerViewId Identifier of the container whose fragment(s) are |
| 66 | * to be replaced. |
| 67 | * @param fragment The new fragment to place in the container. |
| 68 | * @param tag Optional tag name for the fragment, to later retrieve the |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 69 | * fragment with {@link FragmentManager#findFragmentByTag(String) |
| 70 | * FragmentManager.findFragmentByTag(String)}. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 71 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 72 | * @return Returns the same FragmentTransaction instance. |
| 73 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 74 | public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment, |
| 75 | String tag); |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 76 | |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Remove an existing fragment. If it was added to a container, its view |
| 79 | * is also removed from that container. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 80 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 81 | * @param fragment The fragment to be removed. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 82 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 83 | * @return Returns the same FragmentTransaction instance. |
| 84 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 85 | public abstract FragmentTransaction remove(Fragment fragment); |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 86 | |
Dianne Hackborn | f121be7 | 2010-05-06 14:10:32 -0700 | [diff] [blame] | 87 | /** |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 88 | * Hides an existing fragment. This is only relevant for fragments whose |
| 89 | * views have been added to a container, as this will cause the view to |
| 90 | * be hidden. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 91 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 92 | * @param fragment The fragment to be hidden. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 93 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 94 | * @return Returns the same FragmentTransaction instance. |
| 95 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 96 | public abstract FragmentTransaction hide(Fragment fragment); |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 97 | |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 98 | /** |
Jim Shuma | baa1553 | 2010-11-09 20:37:03 -0800 | [diff] [blame] | 99 | * Shows a previously hidden fragment. This is only relevant for fragments whose |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 100 | * views have been added to a container, as this will cause the view to |
| 101 | * be shown. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 102 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 103 | * @param fragment The fragment to be shown. |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 104 | * |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 105 | * @return Returns the same FragmentTransaction instance. |
| 106 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 107 | public abstract FragmentTransaction show(Fragment fragment); |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
Dianne Hackborn | 47c4156 | 2011-04-15 19:00:20 -0700 | [diff] [blame] | 110 | * Detach the given fragment from the UI. This is the same state as |
| 111 | * when it is put on the back stack: the fragment is removed from |
| 112 | * the UI, however its state is still being actively managed by the |
| 113 | * fragment manager. When going into this state its view hierarchy |
| 114 | * is destroyed. |
| 115 | * |
| 116 | * @param fragment The fragment to be detached. |
| 117 | * |
| 118 | * @return Returns the same FragmentTransaction instance. |
| 119 | */ |
| 120 | public abstract FragmentTransaction detach(Fragment fragment); |
| 121 | |
| 122 | /** |
Paul Quei | 355297c | 2014-03-14 15:54:15 +0800 | [diff] [blame] | 123 | * Re-attach a fragment after it had previously been detached from |
Dianne Hackborn | 47c4156 | 2011-04-15 19:00:20 -0700 | [diff] [blame] | 124 | * the UI with {@link #detach(Fragment)}. This |
| 125 | * causes its view hierarchy to be re-created, attached to the UI, |
| 126 | * and displayed. |
| 127 | * |
| 128 | * @param fragment The fragment to be attached. |
| 129 | * |
| 130 | * @return Returns the same FragmentTransaction instance. |
| 131 | */ |
| 132 | public abstract FragmentTransaction attach(Fragment fragment); |
| 133 | |
| 134 | /** |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 135 | * @return <code>true</code> if this transaction contains no operations, |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 136 | * <code>false</code> otherwise. |
Adam Powell | 2b6230e | 2010-09-07 17:55:25 -0700 | [diff] [blame] | 137 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 138 | public abstract boolean isEmpty(); |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 139 | |
Dianne Hackborn | 5ae74d6 | 2010-05-19 19:14:57 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Bit mask that is set for all enter transitions. |
Dianne Hackborn | f121be7 | 2010-05-06 14:10:32 -0700 | [diff] [blame] | 142 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 143 | public static final int TRANSIT_ENTER_MASK = 0x1000; |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 144 | |
Dianne Hackborn | f121be7 | 2010-05-06 14:10:32 -0700 | [diff] [blame] | 145 | /** |
| 146 | * Bit mask that is set for all exit transitions. |
| 147 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 148 | public static final int TRANSIT_EXIT_MASK = 0x2000; |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 149 | |
Dianne Hackborn | f121be7 | 2010-05-06 14:10:32 -0700 | [diff] [blame] | 150 | /** Not set up for a transition. */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 151 | public static final int TRANSIT_UNSET = -1; |
Dianne Hackborn | f121be7 | 2010-05-06 14:10:32 -0700 | [diff] [blame] | 152 | /** No animation for transition. */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 153 | public static final int TRANSIT_NONE = 0; |
Chet Haase | 9ff82bf | 2010-10-05 14:30:51 -0700 | [diff] [blame] | 154 | /** Fragment is being added onto the stack */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 155 | public static final int TRANSIT_FRAGMENT_OPEN = 1 | TRANSIT_ENTER_MASK; |
Chet Haase | 9ff82bf | 2010-10-05 14:30:51 -0700 | [diff] [blame] | 156 | /** Fragment is being removed from the stack */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 157 | public static final int TRANSIT_FRAGMENT_CLOSE = 2 | TRANSIT_EXIT_MASK; |
Dianne Hackborn | 327fbd2 | 2011-01-17 14:38:50 -0800 | [diff] [blame] | 158 | /** Fragment should simply fade in or out; that is, no strong navigation associated |
| 159 | * with it except that it is appearing or disappearing for some reason. */ |
| 160 | public static final int TRANSIT_FRAGMENT_FADE = 3 | TRANSIT_ENTER_MASK; |
Chet Haase | 811ed106 | 2010-08-06 10:38:15 -0700 | [diff] [blame] | 161 | |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 162 | /** @hide */ |
| 163 | @IntDef({TRANSIT_NONE, TRANSIT_FRAGMENT_OPEN, TRANSIT_FRAGMENT_CLOSE, TRANSIT_FRAGMENT_FADE}) |
| 164 | @Retention(RetentionPolicy.SOURCE) |
| 165 | public @interface Transit {} |
| 166 | |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 167 | /** |
| 168 | * Set specific animation resources to run for the fragments that are |
Chet Haase | bc37784 | 2011-03-22 11:35:22 -0700 | [diff] [blame] | 169 | * entering and exiting in this transaction. These animations will not be |
| 170 | * played when popping the back stack. |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 171 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 172 | public abstract FragmentTransaction setCustomAnimations(@AnimatorRes int enter, |
| 173 | @AnimatorRes int exit); |
Chet Haase | bc37784 | 2011-03-22 11:35:22 -0700 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * Set specific animation resources to run for the fragments that are |
| 177 | * entering and exiting in this transaction. The <code>popEnter</code> |
| 178 | * and <code>popExit</code> animations will be played for enter/exit |
| 179 | * operations specifically when popping the back stack. |
| 180 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 181 | public abstract FragmentTransaction setCustomAnimations(@AnimatorRes int enter, |
| 182 | @AnimatorRes int exit, @AnimatorRes int popEnter, @AnimatorRes int popExit); |
Chet Haase | bc37784 | 2011-03-22 11:35:22 -0700 | [diff] [blame] | 183 | |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 184 | /** |
| 185 | * Select a standard transition animation for this transaction. May be |
| 186 | * one of {@link #TRANSIT_NONE}, {@link #TRANSIT_FRAGMENT_OPEN}, |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 187 | * {@link #TRANSIT_FRAGMENT_CLOSE}, or {@link #TRANSIT_FRAGMENT_FADE}. |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 188 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 189 | public abstract FragmentTransaction setTransition(@Transit int transit); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 190 | |
| 191 | /** |
George Mount | c03da0e | 2014-08-22 17:04:02 -0700 | [diff] [blame] | 192 | * Used with to map a View from a removed or hidden Fragment to a View from a shown |
| 193 | * or added Fragment. |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 194 | * @param sharedElement A View in a disappearing Fragment to match with a View in an |
| 195 | * appearing Fragment. |
George Mount | 0a2ae00 | 2014-06-23 14:57:27 +0000 | [diff] [blame] | 196 | * @param name The transitionName for a View in an appearing Fragment to match to the shared |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 197 | * element. |
| 198 | */ |
George Mount | 448bace | 2014-08-18 16:27:43 -0700 | [diff] [blame] | 199 | public abstract FragmentTransaction addSharedElement(View sharedElement, String name); |
| 200 | |
| 201 | /** |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 202 | * Set a custom style resource that will be used for resolving transit |
| 203 | * animations. |
| 204 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 205 | public abstract FragmentTransaction setTransitionStyle(@StyleRes int styleRes); |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 206 | |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 207 | /** |
| 208 | * Add this transaction to the back stack. This means that the transaction |
| 209 | * will be remembered after it is committed, and will reverse its operation |
| 210 | * when later popped off the stack. |
| 211 | * |
| 212 | * @param name An optional name for this back stack state, or null. |
| 213 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 214 | public abstract FragmentTransaction addToBackStack(@Nullable String name); |
Dianne Hackborn | dd913a5 | 2010-07-22 12:17:04 -0700 | [diff] [blame] | 215 | |
| 216 | /** |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 217 | * Returns true if this FragmentTransaction is allowed to be added to the back |
| 218 | * stack. If this method would return false, {@link #addToBackStack(String)} |
| 219 | * will throw {@link IllegalStateException}. |
| 220 | * |
| 221 | * @return True if {@link #addToBackStack(String)} is permitted on this transaction. |
| 222 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 223 | public abstract boolean isAddToBackStackAllowed(); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Disallow calls to {@link #addToBackStack(String)}. Any future calls to |
| 227 | * addToBackStack will throw {@link IllegalStateException}. If addToBackStack |
| 228 | * has already been called, this method will throw IllegalStateException. |
| 229 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 230 | public abstract FragmentTransaction disallowAddToBackStack(); |
Adam Powell | 0c24a55 | 2010-11-03 16:44:11 -0700 | [diff] [blame] | 231 | |
| 232 | /** |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 233 | * Set the full title to show as a bread crumb when this transaction |
| 234 | * is on the back stack, as used by {@link FragmentBreadCrumbs}. |
| 235 | * |
| 236 | * @param res A string resource containing the title. |
| 237 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 238 | public abstract FragmentTransaction setBreadCrumbTitle(@StringRes int res); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 239 | |
| 240 | /** |
| 241 | * Like {@link #setBreadCrumbTitle(int)} but taking a raw string; this |
| 242 | * method is <em>not</em> recommended, as the string can not be changed |
| 243 | * later if the locale changes. |
| 244 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 245 | public abstract FragmentTransaction setBreadCrumbTitle(CharSequence text); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 246 | |
| 247 | /** |
| 248 | * Set the short title to show as a bread crumb when this transaction |
| 249 | * is on the back stack, as used by {@link FragmentBreadCrumbs}. |
| 250 | * |
| 251 | * @param res A string resource containing the title. |
| 252 | */ |
George Mount | 27b3ae6 | 2015-10-16 12:36:58 -0700 | [diff] [blame] | 253 | public abstract FragmentTransaction setBreadCrumbShortTitle(@StringRes int res); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 254 | |
| 255 | /** |
| 256 | * Like {@link #setBreadCrumbShortTitle(int)} but taking a raw string; this |
| 257 | * method is <em>not</em> recommended, as the string can not be changed |
| 258 | * later if the locale changes. |
| 259 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 260 | public abstract FragmentTransaction setBreadCrumbShortTitle(CharSequence text); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 261 | |
| 262 | /** |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 263 | * Schedules a commit of this transaction. The commit does |
Dianne Hackborn | dd913a5 | 2010-07-22 12:17:04 -0700 | [diff] [blame] | 264 | * not happen immediately; it will be scheduled as work on the main thread |
| 265 | * to be done the next time that thread is ready. |
| 266 | * |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 267 | * <p class="note">A transaction can only be committed with this method |
| 268 | * prior to its containing activity saving its state. If the commit is |
| 269 | * attempted after that point, an exception will be thrown. This is |
| 270 | * because the state after the commit can be lost if the activity needs to |
| 271 | * be restored from its state. See {@link #commitAllowingStateLoss()} for |
| 272 | * situations where it may be okay to lose the commit.</p> |
Hemal Patel | a8e1c75 | 2016-08-08 16:19:46 -0700 | [diff] [blame] | 273 | * |
Dianne Hackborn | dd913a5 | 2010-07-22 12:17:04 -0700 | [diff] [blame] | 274 | * @return Returns the identifier of this transaction's back stack entry, |
| 275 | * if {@link #addToBackStack(String)} had been called. Otherwise, returns |
| 276 | * a negative number. |
| 277 | */ |
Dianne Hackborn | ab36acb | 2010-11-05 14:12:11 -0700 | [diff] [blame] | 278 | public abstract int commit(); |
| 279 | |
| 280 | /** |
| 281 | * Like {@link #commit} but allows the commit to be executed after an |
| 282 | * activity's state is saved. This is dangerous because the commit can |
| 283 | * be lost if the activity needs to later be restored from its state, so |
| 284 | * this should only be used for cases where it is okay for the UI state |
| 285 | * to change unexpectedly on the user. |
| 286 | */ |
| 287 | public abstract int commitAllowingStateLoss(); |
Adam Powell | 8585ed6 | 2016-02-04 15:38:20 -0800 | [diff] [blame] | 288 | |
| 289 | /** |
| 290 | * Commits this transaction synchronously. Any added fragments will be |
| 291 | * initialized and brought completely to the lifecycle state of their host |
| 292 | * and any removed fragments will be torn down accordingly before this |
| 293 | * call returns. Committing a transaction in this way allows fragments |
| 294 | * to be added as dedicated, encapsulated components that monitor the |
| 295 | * lifecycle state of their host while providing firmer ordering guarantees |
| 296 | * around when those fragments are fully initialized and ready. Fragments |
| 297 | * that manage views will have those views created and attached. |
| 298 | * |
| 299 | * <p>Calling <code>commitNow</code> is preferable to calling |
| 300 | * {@link #commit()} followed by {@link FragmentManager#executePendingTransactions()} |
| 301 | * as the latter will have the side effect of attempting to commit <em>all</em> |
| 302 | * currently pending transactions whether that is the desired behavior |
| 303 | * or not.</p> |
| 304 | * |
| 305 | * <p>Transactions committed in this way may not be added to the |
| 306 | * FragmentManager's back stack, as doing so would break other expected |
| 307 | * ordering guarantees for other asynchronously committed transactions. |
| 308 | * This method will throw {@link IllegalStateException} if the transaction |
| 309 | * previously requested to be added to the back stack with |
| 310 | * {@link #addToBackStack(String)}.</p> |
| 311 | * |
| 312 | * <p class="note">A transaction can only be committed with this method |
| 313 | * prior to its containing activity saving its state. If the commit is |
| 314 | * attempted after that point, an exception will be thrown. This is |
| 315 | * because the state after the commit can be lost if the activity needs to |
| 316 | * be restored from its state. See {@link #commitAllowingStateLoss()} for |
| 317 | * situations where it may be okay to lose the commit.</p> |
| 318 | */ |
| 319 | public abstract void commitNow(); |
| 320 | |
| 321 | /** |
| 322 | * Like {@link #commitNow} but allows the commit to be executed after an |
| 323 | * activity's state is saved. This is dangerous because the commit can |
| 324 | * be lost if the activity needs to later be restored from its state, so |
| 325 | * this should only be used for cases where it is okay for the UI state |
| 326 | * to change unexpectedly on the user. |
| 327 | */ |
| 328 | public abstract void commitNowAllowingStateLoss(); |
Dianne Hackborn | 2dedce6 | 2010-04-15 14:45:25 -0700 | [diff] [blame] | 329 | } |