I have this code to change fragment:
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction()
.replace(R.id.frame_content, fragment);
if (isBackable) fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
Android studio warn:
This transaction should be completed with a commit() call
I don't know how the correct way to solve this warning.
It's a false positive.
Android Lint only sees you have chained some fragment transaction calls together without a commit but fails to see the commit on a later row.
You can either
ignore the warning,
suppress it with @SuppressLint("CommitTransaction")
, or
remove the method chaining i.e. replace
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction()
.replace(R.id.frame_content, fragment);
with
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.replace(R.id.frame_content, fragment);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With