A
A
Anton Shelestov2020-04-15 18:03:20
Android
Anton Shelestov, 2020-04-15 18:03:20

OnBackPressed, how to find out which activity the user came from?

Hello!
Guys, tell me please, is it possible to somehow programmatically determine with which activity the user came by pressing the "Back" button (onBackPressed)

Ie . For example, there is one main activity and 5 child ones, so to speak.
The user from the main goes to the child and then comes back. And I need to determine which child it came from in order to update the content in the main activity according to its changes in the child.

Is it possible to do this?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alina Mitrokhina, 2020-04-15
@fursa08

Immediately comes to mind. You just override when the onBackPressed method you pass an Intent to start another Activity. Just add the name of the Activity to the extras parameter. I hope it helped

D
Dmtm, 2020-04-16
@Dmtm

getting results on onBackPressed is a very, very bad idea
, in short, you need an additional button like Ok, and rejecting changes on onBackPressed
, and, well, launching children via statrtActivityForResult

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question