Reputation: 5121
I am having the below set of Activities :
Activity 1 -> Activity 2 -> Activity 3
I have launched Activity 2 from Activity 1 using startActivityForResult and after some work in Activity 2, I finished Activity 2 and started Activity 3 from Activity 2 using same startActivityForResult.
Now when I press back button on Activity 3, I want to handle the result in onActivityResult of Activity 1. The control is going in Activity 3 but the result code is coming as 0, so I have added setResult in Activity 3 on backPressed but it is still giving the result code as 0 in Activity 1.
How can I do this, please help me If anyone know about this.
Thanks a lot in advanced.
Upvotes: 1
Views: 84
Reputation: 787
Don't finish the activity2 when you launch the Activty3, so you can get the result in activity2's onActivityResult
method, at that time you set again the same setResult
method with the data you get from Activity3 and finish activity2 here, so now you get the result in Activity1.
your reverse flow like this:
Activity3 ->setResult ->finish activity3 -> onAcitvityResult in Activity2 -> get the data and setResult -> finisht acitvity2 -> onAvtivityResult in Activity1
Upvotes: 0
Reputation: 2805
Don't finish activity2 when going to activity 3. Instead of finish activity 2 when you came on onActivityResult of Activity2, and again sent result back to Activity 1
Upvotes: 3