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 7166067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:21:12+00:00 2026-05-28T14:21:12+00:00

I am currently having trouble getting a value from an AsyncTask that gets data

  • 0

I am currently having trouble getting a value from an AsyncTask that gets data from a JSON connection. I have looked at a few examples, but mostly I have only seen posting results from AsyncTask.

First I have an object called Dog that only has a String, Name. I am trying to get the Name of the dog from the server.
Using the following code in my oncreate, I start the DogAsyncTask while assing in an URL called n and a Dog d_in.

    Dog d_in = new Dog("DogName");
    DogAsyncTask task = new DogAsyncTask(d_in);
    String n = "www.dog.com";
    task.execute(n);
    Log.e("Out", d_in.getName());

My AsyncTask is as follows:

 private class DogAsyncTask extends AsyncTask<String, Void, String> {

    Dog d = null;

    DogAsyncTask(Dog d){
        this.d = d;
    }

    ProgressDialog mProgressDialog;
    @Override
    protected void onPostExecute(String result) {
        d.setName(result);
        Log.e("Dog", d.getName());
        mProgressDialog.dismiss();
    }

    @Override
    protected void onPreExecute() {
        mProgressDialog = ProgressDialog.show(AsyncTestActivity.this, "Loading...", "Data is Loading...");
    }

    @Override
    protected String doInBackground(String... name) {
        //Go to url = name and then gets String below.
        String outfromjson = "new dog name";  //This will be a function that gets a name from JSON
        return outfromjson;
    }
}

I tried using something like
Log.e(“Out”, task.d.getName());
but I keep getting the default name of the dog which is “DogName”. How to I carry values out of AsyncTask?

  • 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-05-28T14:21:13+00:00Added an answer on May 28, 2026 at 2:21 pm

    OK, The thing what is happening here is:

    You want to pass Dog as reference (pointers as in C / C++ / Objective-C),
    and you want to reflect change in original variable using other variable.

    but keep in mind that Java doesn’t pass object by reference, Java passes objects by value (only value is transferred, another object is created and assigned value).

    So what you can do is you can assign that result-holder object again as a value to the original object.

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

Sidebar

Related Questions

I'm currently having trouble creating an image from a binary string of data in
I'm having trouble inserting data from my registration webform into sqlserver-2008. I'm getting an
I'm developing a RESTful WCF, and am currently having trouble getting nice, clean JSON-serialized
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
I am currently having trouble getting rid of a sliver of white... Here is
I have managed to parse ok. But now I am having trouble getting the
I am having trouble getting the selected value in an asp:DropDownList. I am using
I am getting some data from the net, which gets parsed with JSoup in
i'm having trouble getting the date to be imported into mysql from my form.

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.