Like i can send data from one activity to another using this:
intent.putExtra("Name", Value);
how can i send data when i am using finish()
to get back to the previous activity.
In my app from Activity_A
i am going to Activity_B
. In Activity_B
i am marking a location on map, which gives me latitude and longitude. Then i want to use this lat and lng in Activity_A
. But i don't want to get back to Activity_A
using an intent, because i don't want to recreate the Activity_A
since some data already filled will be lost.
use
startActivityForResult
to start B andsetResult
before Bfinish
and handleonAcitivityResult
in ACall your
Activity_B
withstartActivityForResult()
, from yourActivity_A
:Once you finished working on the
Activity_B
, you callsetResult()
to set the data, followed byfinish()
like thisThis will bring you back to your previous
Activity_A
.In
Activity_A
, overrideonActivityResult()
.Found here
In Activity A:
In Activity B:
As you are using
intent.putExtra("Name", Value);
, use the same thing while finishing the activity also.For ex.:
From activityA you call activityB like:
And from activityB, while finishing the activity, call:
Now in activityA, your
onActivityResult
will be called, which is like:So inthis way you can handle it.