A fragment transaction is begun and never committed

tx0/kotlin:fragment-transaction-not-committedrecommendedwarningframeworks/androiddepth fastbug, android

What it finds

supportFragmentManager.beginTransaction().replace(R.id.content, screen) prepares a transaction and drops it: nothing changes on screen until it is committed. The commit { ... } extension commits by itself.

From the rule's source, transaction_not_committed.rs.

Example from the rule's tests
fun show(manager: FragmentManager, screen: Fragment) {    manager.beginTransaction().replace(R.id.content, screen)tx0 reports: the fragment transaction is never committed    manager.beginTransaction().replace(R.id.content, screen).commit()    manager.beginTransaction().add(screen, "tag").commitAllowingStateLoss()}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:fragment-transaction-not-committed" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:fragment-transaction-not-committed] reason="..."

tx0 explain tx0/kotlin:fragment-transaction-not-committed shows the same in the terminal. Found a false positive? Report it.