What is the difference between finish() and supportFinishAfterTransition()?

149 Views Asked by At

So I have a button in activity 1 that when it is clicked, the apps goes to activity 2 using intent. So here in activity 2, I have programmed that when on back is pressed, return to activity 1. I have done the two following functions, but both of them apparently are doing exactly the same (They make the app to go back to activity 1 correctly), so I just want to know the difference between them:

//first function
    @Override
    public void onBackPressed() {
        supportFinishAfterTransition();
    }

//second function

    @Override
    public void onBackPressed() {
    finish();
    }
1

There are 1 best solutions below

0
JayC667 On

https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity

States that

supportFinishAfterTransition

fun supportFinishAfterTransition(): Unit

Reverses the Activity Scene entry Transition and triggers the calling Activity to reverse its exit Transition. When the exit Transition completes, finish is called. If no entry Transition was used, finish() is called immediately and the Activity exit Transition is run.

On Android 4.4 or lower, this method only finishes the Activity with no special exit transition.

This is for Kotlin, but I really expect Java to behave in the same way.