Is this correct regarding fragment state loss transactions for safe transactions?

24 views Asked by At

is

if (isStateSaved()) {
 commitAllowingStateLoss()
} else {
 commit()
}

same as

commitAllowingStateLoss()

As the method internals are the same with only diff of throwing IllegalStateException?

If yes, then why in this fragment helper made by vasiliy he does so :

    private void commitFragmentTransactionSafely(FragmentTransaction ft) {
        // TODO: add mechanism for notifications about commits that allow state loss
        if (mFragmentManager.isStateSaved()) {
            // We acknowledge the possibility of losing this transaction if the app undergoes
            // save&restore flow after it is committed.
            ft.commitAllowingStateLoss();
        } else {
            ft.commit();
        }
    }

source : https://github.com/techyourchance/fragment-helper/blob/367c55b1d654a1e4f28e27d176c1902f0c4baee6/fragmenthelper/src/main/java/com/techyourchance/fragmenthelper/FragmentHelper.java#L12

and rclone guys also do this : https://github.com/x0b/rcx/blob/master/app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/Dialogs.java

0

There are 0 answers

Related Questions in ILLEGALSTATEEXCEPTION