I created an Activity which contains swipe fragments. Inside one fragment, I have a button with an onClick listener which starts an activity for intent (I called it gallery intent, because I want to choose a picture from my phone in it). As the fragment cant receive the result of this intent, I am calling it inside the container activity. I safe the URI in sharedpreferences, and back inside my fragment (inside the onclick method) I check the sharedpreferences. The problem is, that i have to click on the button again in order to see the image. How can I tell my onClick method that it should wait with finishing until the sharedpreferences is updated? Here my code snippet from the fragment:
A method must never wait for some UI activity to finish. That's a big NO-NO in any GUI development, on Android and elsewhere. Any event handlers must return quickly, lest they block the UI thread.
You need to override the onActivityResult and perform any desired action in that.