Condividi tramite


FragmentTransaction.CommitNow Method

Definition

Commits this transaction synchronously.

[Android.Runtime.Register("commitNow", "()V", "GetCommitNowHandler", ApiSince=24)]
public abstract void CommitNow ();
[<Android.Runtime.Register("commitNow", "()V", "GetCommitNowHandler", ApiSince=24)>]
abstract member CommitNow : unit -> unit
Attributes

Remarks

Commits this transaction synchronously. Any added fragments will be initialized and brought completely to the lifecycle state of their host and any removed fragments will be torn down accordingly before this call returns. Committing a transaction in this way allows fragments to be added as dedicated, encapsulated components that monitor the lifecycle state of their host while providing firmer ordering guarantees around when those fragments are fully initialized and ready. Fragments that manage views will have those views created and attached.

Calling commitNow is preferable to calling #commit() followed by FragmentManager#executePendingTransactions() as the latter will have the side effect of attempting to commit <em>all</em> currently pending transactions whether that is the desired behavior or not.

Transactions committed in this way may not be added to the FragmentManager's back stack, as doing so would break other expected ordering guarantees for other asynchronously committed transactions. This method will throw IllegalStateException if the transaction previously requested to be added to the back stack with #addToBackStack(String).

<p class="note">A transaction can only be committed with this method prior to its containing activity saving its state. If the commit is attempted after that point, an exception will be thrown. This is because the state after the commit can be lost if the activity needs to be restored from its state. See #commitAllowingStateLoss() for situations where it may be okay to lose the commit.</p>

Java documentation for android.app.FragmentTransaction.commitNow().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to