In an activity (say A) I have to perform a certain task depending on the result of another activity (B). I start activity B using startActivityForResult(). The pseudo code is something like this:
(in activity A)
//Statements
//startActivityForResult(activityB)
//get the result in some local variable for activity A. result is a boolean
//if(result==true) do something
//else do something else
Now the problem I’m facing is that after starting the activity B, it doesn’t wait for the result to arrive from B. Instead, it proceeds and uses the default value of the boolean result.
Any solution?
If this particular block was in another thread, i could write a synchronized block and
issue a wait() after starting the activity B, and then notify() in the onActivityResult().
But since there’s just a single thread, that’s not an option right?
Should mention that activityB takes a user input of Yes/No and returns that. So on starting it, the result is not immediately available
Put your last two lines from your code listing in
onActivityResult(), as is described in the Android documentation.More importantly, you also need to rewrite activityB to actually follow the instructions for using
setResult()to pass results back to activityA.