4

I am used to IOS development and there are unwind segues in Swift to exit to a certain view controller from the present view controller.

(If there is any) What is equivelant of Unwind segue in Android Development? What should I do to go back to a certain activity?

B.Y
  • 321
  • 1
  • 4
  • 14

1 Answers1

1

This is handled in onBackPressed() of your Activity, which you can override if you want to do anything special. If you want finer control or more detail, you can read up on FragmentManager, which manages the backstack. popBackStack() and popBackStackImmediate() may be what you're looking for. Generally you shouldn't have to micromanage this too much. By default it'll take you back to the previous activity with no effort on your part.

One thing to take note of as an iOS dev jumping into Android, is there's a difference between back (the button at the bottom), and up (the button in the toolbar up top). The back button takes you back to the previous screen you saw(even to other apps), closes the keyboard, or dismisses certain windows. The up button basically returns you to the main screen of the app, popping the whole backstack. There's some fine points here, which Google does an excellent job explaining in the design guidelines.

Jim Pekarek
  • 7,270
  • 6
  • 33
  • 34
  • but an unwind segue doesn't necessarily correlate to the back button of android. You can unwind for an existing controller on the stack, you return to that instance. I am not sure if you can do this consistently with android. I have experimenting with flags, but it instantiate a new instance which is not the same as an unwind segue which you return to a previous instance at the top of the stack – Gustavo Baiocchi Costa Dec 21 '21 at 11:14