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.
You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.
Put the data that you want to send back to the previous activity into an Intent . The data is stored in the Intent using a key-value pair. Set the result to RESULT_OK and add the intent holding your data. Call finish() to close the Second Activity.
Intent data = new Intent(); data. putExtra("myData1", "Data 1 value"); data. putExtra("myData2", "Data 2 value"); // Activity finished ok, return the data setResult(RESULT_OK, data); finish();
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With