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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:11:35+00:00 2026-06-08T13:11:35+00:00

Here I am trying to retrieve the response from the server and display it,

  • 0

Here I am trying to retrieve the response from the server and display it, but I am failed to do so, the response text does not appear in my text view, insetead the default value of the string does, may I ask how can I achieve my goal. And why my code cannot finish the task.

Here is my android program:

public class Chico extends Activity {

GrabURL grab;
TextView mRespond;
String line;

@Override
public void onCreate(Bundle savedInstanceState) {

    //create the activity
    super.onCreate(savedInstanceState);

    //set up the layout
    setContentView(R.layout.activity_chico);

    mRespond = (TextView) findViewById(R.id.Respond);
    mRespond.setVisibility(View.GONE);

    grab = new GrabURL();
      line = "line";

    //set up the button for check in
    Button btnin = (Button) findViewById(R.id.inbutton);
    btnin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //set the values
            grab.onPreExecute("TechID", Build.SERIAL);
            grab.onPreExecute("Type", "Checkin");
            //set the destination and send the request
            grab.execute(new String[]{"http://192.168.1.150/Me/testing.php"});
            //close the activity
            mRespond.setVisibility(View.VISIBLE);
            mRespond.setText(line);
            //finish();
        }
    }); 
}

private class GrabURL extends AsyncTask<String, Void, Void>{
    //ArrayList object for storing the string pairs
    ArrayList<NameValuePair> nameValuePairs;

    public GrabURL() { 
        //constructor of the class
        nameValuePairs = new ArrayList<NameValuePair>(); 
      } 


    protected void onPreExecute(String key, String value) {
        //store the pair of values into the ArrayList 
        nameValuePairs.add(new BasicNameValuePair(key,value));
        }

    @Override
    protected Void doInBackground(String... urls) {
        // TODO Auto-generated method stub
        //Operation being executed in another thread
        try{
            //set up the type of HTTPClient
            HttpClient client = new DefaultHttpClient();
            //set up the location of the server
            HttpPost post = new HttpPost(urls[0]);
            //translate form of pairs to UrlEncodedFormEntity 
            UrlEncodedFormEntity ent = new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8);
            //set up the entity being sent by post method
            post.setEntity(ent);
            //execute the url and post the values
            HttpResponse responsePOST = client.execute(post); 
            HttpEntity resEntity = responsePOST.getEntity();
            line = EntityUtils.toString(resEntity);
         } catch (Exception e) {
             //catch the exception
            line = "Can't connect to server";
         }
        return null;
    }

    protected void onPostExecute(Void unused) {
        Toast.makeText(getApplicationContext(), "Value updated", Toast.LENGTH_SHORT).show();
    }
    }

}

And here is the php file, it just prints a line:

<?php
print "testing";    
?>
  • 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-08T13:11:38+00:00Added an answer on June 8, 2026 at 1:11 pm

    Move this code to your AsyncTask‘s onPostExecute():

    ...
    mRespond.setVisibility(View.VISIBLE);
    mRespond.setText(line);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to retrieve image file from my local server. Here is my (very
I am trying to retrieve a value from an Array. Here is the code:
I am trying to retrieve values from Json Object but getting Exception.I am trying
I'm trying to retrieve JSON data from servlet and display in html. I was
I am trying to display JSON data that I retrieve from an ajax call
I am trying to retrieve the file from sharepoint to local hard disk. Here
I'm trying to retrieve a single entity from a Linq2Sql query, but I'm having
Okay the title may not justify what I'm trying to do here but dont
I am trying to save and retrieve an Image from HTTPRuntime Cache but I
Very new mobile developer here... I am trying to retrieve a list of tweets

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.