How Do I Go Back to Previous Activity on Android?
Contents

Answer #2: You can go back to the previous activity by just calling finish() in the activity you are on. Note any code after the finish() call will be run – you can just do a return after calling finish() to fix this.

How do you close an activity on Android?

You have set android:noHistory = “true” for MainActivity inside AndroidManifest. xml which causes MainActivity to finish automatically on pressing the back key. Before switching to your ‘SettingsActivity’, you have called finish() in your MainActivity , which kills it.

How do you finish an activity?

How to use finish method in android. app. Activity

  1. WeakReference mActivity;mActivity.get()
  2. Stack activityStack;activityStack.lastElement()
  3. (Activity) param.thisObject.
Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest