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.