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.
More Related Contents:
- How can I put a ListView into a ScrollView without it collapsing?
- IOException: read failed, socket might closed – Bluetooth on Android 4.3
- Auto-fit TextView for Android
- Android webview slow
- Playing a video in VideoView in Android
- Selector on background color of TextView
- Unable to add window — token android.os.BinderProxy is not valid; is your activity running?
- Failed binder transaction when putting an bitmap dynamically in a widget
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.Gallery$LayoutParams
- Make an Android button change background on click through XML
- How to access Fragment’s child views inside fragment’s parent Activity?
- Flutter does not find android sdk
- how to set google map fragment inside scroll view
- Android 2.3 wifi hotspot API
- How to use the Renderscript Support Library with Gradle
- Android multiple line notification like Gmail app
- Google Drive\Docs API for Android
- Get the co-ordinates of a touch event on Android
- Android: Unicode/Charset problems when sending an SMS (sendTextMessage)
- How do I debug an APK that is signed for release?
- failed to find Build Tools revision 21.1.1 – sdk up to date
- Can a selector resource use a color defined in a style?
- Getting screen width on API Level 30 (Android 11): getDefaultDisplay() and getMetrics() are now deprecated. What should we use instead?
- LayoutManager for RecyclerView Grid with different cell width
- Emulator problem in Android
- Keyboard hides BottomSheetDialogFragment
- Keytool alias does not exist
- AlarmManager setExact with WakefulBroadcastReceiver sometimes not exact
- Access android context in ndk application
- Is there another place to get a google-services.json?