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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:57:18+00:00 2026-06-03T14:57:18+00:00

UPDATE: I found that the easiest way is to use AQuery . I need

  • 0

UPDATE: I found that the easiest way is to use AQuery.

I need to get my HttpPost for getting JSON data on another thread and I dont know how to get it all working together. Ive looked at the Painless Threading Blog and still cant get it to work.

Below is my original code befor trying to ansyncing it.

This is my first try at AsyncTasking so plz dont be to harsh. Thnx.

Inside my OnCreate:

    /**
     * Connecting to MySQL using PHP and Populate the ListView
     * ========================================================
     */
    mList = (ListView) findViewById(R.id.sidebar_list);

    /** - http post for the list - */
    try  //<--THIS TRY METHOD IS WHAT NEED TO BE ON A SEPERATE THREAD??
    {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://192.168.1.34/xxxx/xxxxx_list.php");

    List<NameValuePair> nameValue = new ArrayList<NameValuePair>();
    httpPost.setEntity(new UrlEncodedFormEntity(nameValue));

    HttpResponse httpResponse = httpClient.execute(httpPost);

    HttpEntity httpEntity = httpResponse.getEntity();

    is = httpEntity.getContent();

    } catch (Exception e)
    {
    // TODO handle e
    Log.e("log_tag", "Error in HTTP connect" + e.toString());
    Toast.makeText(this, "HTTP Connection Error : " + e.toString(), Toast.LENGTH_LONG).show();
    }

    // EVERYTHING BELOW HERE CAN BE ON THE UI THREAD???
    /**
     * Convert response to string------------------------------------
     * ----------------------
     * */
    try
    {
    BufferedReader BufR = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
    sb = new StringBuilder();
    sb.append(BufR.readLine() + "\n");

    String line = "0";
    while ((line = BufR.readLine()) != null)
    {
    sb.append(line + "\n");
    }
    is.close();
    result = sb.toString();
    } catch (Exception e)
    {
    // TODO handle e
    Log.e("log_tag", "Error in convert to String" + e.toString());
    }

    // paring data
    int q_id;
    String q_label;
    String q_title;
    String q_description;
    String q_gotoURL;

    try
    {
    jArray = new JSONArray(result);
    JSONObject json_data = null;
    for (int i = 0; i < jArray.length(); i++)
    {
    json_data = jArray.getJSONObject(i);
    q_id = json_data.getInt("_ID");
    q_label = json_data.getString("label");
    q_title = json_data.getString("title");
    q_description = json_data.getString("description");
    q_gotoURL = json_data.getString("gotoURL");
    // mList.add();
    }

    setupList();
    } catch (JSONException e1)
    {
    Toast.makeText(getBaseContext(), "No Data Found", Toast.LENGTH_LONG).show();
    } catch (ParseException e1)
    {
    e1.printStackTrace();
    }

    };
  • 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-03T14:57:19+00:00Added an answer on June 3, 2026 at 2:57 pm

    I think you can try something like this:

    public class MyActivity extends Activity {
    
    // paring data
    int q_id;
    String q_label;
    String q_title;
    String q_description;
    String q_gotoURL;
    Context context;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        mList = (ListView) findViewById(R.id.sidebar_list);
        context = getApplicationContext();
        new HttpTask().execute("http://192.168.1.34/xxxx/xxxxx_list.php");
    
    }
    private class HttpTask extends AsyncTask<String, Void, String> {
    
    
        protected String doInBackground(String... urls) {
            try {
                HttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(urls[0]);
    
                List<NameValuePair> nameValue = new ArrayList<NameValuePair>();
                httpPost.setEntity(new UrlEncodedFormEntity(nameValue));
    
                HttpResponse httpResponse = httpClient.execute(httpPost);
    
                HttpEntity httpEntity = httpResponse.getEntity();
    
                is = httpEntity.getContent();
    
                // Get result
                BufferedReader BufR = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
                sb = new StringBuilder();
                sb.append(BufR.readLine() + "\n");
    
                String line = "0";
                while ((line = BufR.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();
                result = sb.toString();
    
            } catch (Exception e) {
                Toast.makeText(context, "HTTP Connection Error : " + e.toString(), Toast.LENGTH_LONG).show();
                return null;
            }
        }
    
        protected void onPostExecute(String result) {
            try {
                if(result == null)
                    throw new Exception("result is null");
                jArray = new JSONArray(result);
                JSONObject json_data = null;
                for (int i = 0; i < jArray.length(); i++) {
                    json_data = jArray.getJSONObject(i);
                    q_id = json_data.getInt("_ID");
                    q_label = json_data.getString("label");
                    q_title = json_data.getString("title");
                    q_description = json_data.getString("description");
                    q_gotoURL = json_data.getString("gotoURL");
                    // mList.add();
                }
                //send message to handler to draw list
                drawListHandler.sendEmptyMessage(0);
            } catch (Exception e1) {
                Toast.makeText(context, e1.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    }
    
    Handler drawListHandler = new Handler(){
        /* (non-Javadoc)
         * @see android.os.Handler#handleMessage(android.os.Message)
         */
        @Override
        public void handleMessage(Message msg) {
            setupList();
        }
    };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found something that works with updating one field at here: http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-single-sql-query/ UPDATE person
Right guys, all autocomplete plugins and functions that I've found, they only update upon
ETA UPDATE: I've found that if I remove all the transparent .png files from
I am looking for the best way to notify a user that they need
using Microsoft.SqlServer.Management.SqlStudio.Explorer; unable to find this pls assist [update] found the dll's in this
Update Solution Found See Bottom of post if interested Seems simple enough and for
12:18:55,541 INFO [UpdateChecker] New update(s) found: 2.0.0 [ http://ehcache.org/news.html] How do I suppress ehcache
[Update: I've found the API reference. The method used is below] <?php wp_delete_post( $postid,
I found some problem. When i running apc_store and more times update a page
Does anyone know of a way to get the free disk space of a

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.