30

Newbie Question from an iPhone developer.

I have called the startActivity(intent) and the new activity loads. How do I go 'back' to the calling activity once a button is pushed. 'Popping' the activity off the stack basically.

Ian Vink
  • 66,960
  • 104
  • 341
  • 555

3 Answers3

42

If you had created the new Activity with startActivity you just need to call finish. If you had spawned the new Activity by calling startActivityForResults then you need to call setResult and then finish in order to pass back data to the onActivityResult method of the prior Activity.

Tim Kryger
  • 11,166
  • 4
  • 52
  • 41
  • 2
    One more thing, The requestCode is for identifying which call it was. (in cases here you have more than 1 `startActivityForResults`) – st0le Jul 19 '10 at 04:21
6

Call finish() on your newly loaded activity. This is assuming you didn't call finish() on your previous activity (in which case you could always restart it).

Andy Zhang
  • 8,285
  • 1
  • 37
  • 24
2

Calling finish() closes that activity and gets back to the previous screen(or Activity which called that) , or exits the app if that is the main activity which launched app.

Vins
  • 4,089
  • 2
  • 35
  • 50