2

The question is not about how to use startActivityForResult but about the life cycle relating to the finish () event.

I am developing an app in java, android studio.

I have two activitys, A and B, being A my MainActivity.

When I'm in activity B and I press the back button on android (onBackPressed) ...

finish();

I need to do some things in activity A.

The onCreate method is not executed since the activity was already created ... which method can I use?

elyar abad
  • 771
  • 1
  • 8
  • 27
  • do stuff in onResume or start Activity B as startActivityForResult and when you press the back button call the setresult method – Zahoor Saleem Sep 04 '19 at 17:05
  • Possible duplicate of [How to manage startActivityForResult on Android?](https://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android) – Arbaz Pirwani Sep 04 '19 at 17:14

1 Answers1

3

What you need to do is use onActivityResult(...) but for that, you need to specify the startActivityForResult value and send the result on the Activity B

Intent().also { 
    startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST)
}

For more information: https://developer.android.com/training/basics/intents/result

Dinorah Tovar
  • 488
  • 2
  • 15