• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 664
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?
 
Saloon Keeper
Posts: 7591
177
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic