Finishing current activity from a fragment

When working with fragments, instead of using this or refering to the context, always use getActivity(). You should call

Java

getActivity().finish();

Kotlin

activity.finish()

to finish your activity from fragment.

Leave a Comment