Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

How to make a method wait until it receives input

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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: 413
7
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show startActivityForResult code?
 
Saloon Keeper
Posts: 5982
154
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!