In Android, startActivityForResult()
and onActivityResult()
can be used to pass a bundle from an activity to its PARENT_ACTIVITY (ref this question, for instance, or this question). This requires overriding onBackPressed()
to call finish()
instead.
The semantics of this feel "wrong" to me in a case where pressing back isn't about finishing some step in a flow and returning a value. In my case, when the user presses back, they're effectively saying "I changed my mind and want to go back to the previous screen" not "I'm done with the current screen and want to go forward," which is how finish()
feels to me.
Is there another alternative where I just want the activity I'm going back to to know some info about state of the current activity? Or is the consensus in the community that startActivityForResult
is the right way to go, regardless of the semantics/intent?
Details follow:
I am working on an app including two activities centered around Google Maps for Android, SelectActivity
and EditActivity
. SelectActivity
shows multiple points of interst on the map and allows the user to select an existing POI or create a new POI. EditActivity
allows the user to edit details.
EditActivity
is defined in the manifest with SelectActivity
as its PARENT_ACTIVITY, so pressing the back button in EditActivity
returns to SelectActivity
. There are some other activities that allow the user to drill down deeper, after EditActivity
, but they are not relevant to this question.
When SelectActivity
launches EditActivity
, it includes a bundle with the current map parameters in the Intent
, so EditActivity
starts with the same map view as SelectActivity
.
Right now, SelectActivity
sets the map to an area around the device's current location from Location Services. This is the desired behavior in most cases because the user will usually want to be editing things around their immediate location.
However, sometimes users need to edit multiple things somewhere else on earth. Ideally, when SelectActivity
is resumed by returning from EditActivity
, a bundle containing the current map parameters (center, zoom level, etc) would be created and passed, and then SelectActivity
would use the map parameters from that bundle instead of the default device-centered behavior.