• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

How to make a method wait until it receives input

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

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:


 
Rancher
Posts: 660
10
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show startActivityForResult code?
 
Bartender
Posts: 7488
171
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yannik Hoern
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your responses!

Randy Tong wrote:Can you show startActivityForResult code?


Do you mean my onActivityResult? My startActivityFor Result code is only that bit included in my onClick method.

Here is my onActivityResult code:



Ok Tim, do you have an advise what I should include in my onActivityResult?
 
Something about .... going for a swim. With this tiny ad ...
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic