Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:31:16+00:00 2026-06-15T14:31:16+00:00

In some way I do understand the Handler, but I’m not sure what to

  • 0

In some way I do understand the Handler, but I’m not sure what to do with the params and how to let the code wait until the job is done in the background. I want the UI to be normally working and in the background I want to do an exchange rate calculation.

I have the following:

I call new getOnlineExchangeRate().execute(""); //Get Exchange Rate in BG

After that I want to have a result=amount*exchangerate, but the code is not waiting for the result.
Can somebody tell me how the calculation waits till we have an exchangerate. Do I have to send some params and how would that look?

.
.
.
.
.
public double getYahooExchangeRate(String ER){

        double exchangerate=0;

    try {

        s = getJson("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22"+ER+"%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");                       
        //s = getJson("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22"+val[from]+val[to]+"%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");                      

        JSONObject jObj;
        jObj = new JSONObject(s);
        String exResult = jObj.getJSONObject("query").getJSONObject("results").getJSONObject("rate").getString("Rate");

        exchangerate=Double.parseDouble(exResult);

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            ALS.Toast(myContext.getString(R.string.conversionerror), false);
        }
        catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            ALS.Toast(myContext.getString(R.string.conversionerror), false);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            ALS.Toast(myContext.getString(R.string.conversionerror), false);
        }                                   
    return exchangerate;

}       



public String getJson(String url)throws ClientProtocolException, IOException {

StringBuilder build = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String con;
while ((con = reader.readLine()) != null) {
    build.append(con);
}
return build.toString();
}



public class getOnlineExchangeRate extends AsyncTask<String, Void, String> {


      @Override

      protected void onPostExecute(String result) {

        // execution of result of Long time consuming operation
          ALS.Toast(myContext.getString(R.string.exchangeratesupdated), true);


      }


    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
         // perform long running operation operation

         getYahooExchangeRate(USDEUR);
        return null;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:31:18+00:00Added an answer on June 15, 2026 at 2:31 pm

    I think your problem is in this line:

    @Override
    protected String doInBackground(String... params) {
        getYahooExchangeRate(USDEUR);
        return null;
    

    You want to return the result of getYahooExchangeRate and not null 🙂
    So change this and the return-value should be a double. So change this to:

    @Override
    protected Double doInBackground(String... params){
        return getYahooExchangeRate(USDEUR);
    }
    

    You also have to change your class header:

    public class getOnlineExchangeRate extends AsyncTask<String, Void, Double> {
    
    
    AsyncTask<Params, Progress, Result>
    

    The generic part tells the AsyncTask which Informationstypes are handled.
    The first is the type for the params of doInBackground(Params... )
    The second is the type of the progress-Information
    The last explains which type is returned by doInBackground(), so it changes the method-header from

    protected Result doInBackground(Params... params){ };
    

    to
    protected double doInBackground(Params… params){};

    To bring back the Result i would use and Observer oder Callback-Pattern.

    Edit: changed double to Double, because primitives cannot be used for Generics.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand some boost code which is causing PC-Lint grief and uses
Is there some way to define an abstract type as a parameter in an
Is there some way to use Tuning Advisor for SQL Express? Is there some
I need some way to monitor a desktop application and restart it if it
EDIT: There must be some way I can approach this without writing a whole
Is there some way when sending this message to specify that I rather have
Is there some way to compile (with the CSC task) a WPF Application with
is there some way to force the gridview's pager to show up, even when
Is there some way I can catch when a method generates a write to
Is there some way to replicate rails' link-to-unless-current? Ie. if i have a list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.