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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:49:12+00:00 2026-05-27T18:49:12+00:00

I am sending some information from my application to server and waiting for the

  • 0

I am sending some information from my application to server and waiting for the response. Before i send i set my textview for message to display “processing request” and after getting response i display a different message.

This processing message is not getting displayed. Is it beacuse the UI is getting blocked due to other operation.
How to handle this. Threading is not giving correct result as need to display the response.
SO that involve UI in the thread .

 package com.PandG.app.android.activities;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpConnectionParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.PandG.app.android.R;
import com.PandG.app.android.dataAccess.SettingsDBAccess;
import com.PandG.app.android.entity.Job;
import com.PandG.app.android.entity.Settings;
import com.PandG.app.android.services.JobsManager;
import com.lib.android.Utils.Utils;
import com.lib.android.activity.BaseActivity;
import com.lib.android.dataAccess.DatabaseManager;

public class JobCheckoutActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setViewContent();
    }

    private void setViewContent() {

        Settings setting = getSettings();
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.job_checkout);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);
        //new DataProcess().execute(null);
        TextView text1 = (TextView)findViewById(R.id.checkoutmessage);
        text1.setText("Processiong Job Cart ...");
        if(setting!=null){
            TextView text2 = (TextView)findViewById(R.id.checkoutheading);
            text2.setVisibility(View.GONE);
            Button homeButton = (Button)findViewById(R.id.gohome);
            homeButton.setVisibility(View.GONE);
        JSONObject jobObject =encodeData(setting);
        sendDataToServer(jobObject);
        } 

    }
    private void sendDataToServer(JSONObject jobObject) {
        TextView text1 = (TextView)findViewById(R.id.checkoutmessage);
        text1.setText("Processiong Job Cart ...");
        HttpClient client = new DefaultHttpClient();
        HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout
                                                                                // Limit
        HttpResponse response;
        try {
            HttpPost post = new HttpPost(Utils.getPostUrl());
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("orderparameters",
                    jobObject.toString()));
            Log.i("Job ORDER", jobObject.toString());
            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            response = client.execute(post);
            checkResponseFromServer(response);
            ClearCart();
        } catch (Exception e) {
            Log.w("error", "connection failed");
            Toast.makeText(this, "Order not placed due to connection error",
                    Toast.LENGTH_LONG);
            e.printStackTrace();

        }

    }

    private void ClearCart() {
        JobsManager.JobsCartList.clear();

    }

    private void checkResponseFromServer(HttpResponse response) {
        try {
            if (response != null) {
                InputStream in = response.getEntity().getContent();
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(in));

                String line;
                StringBuffer buffer = new StringBuffer();

                while ((line = reader.readLine()) != null) {
                    buffer.append(line);

                }

                in.close();

                JSONObject jsonResponse = new JSONObject(buffer.toString());
                Log.i("Status", jsonResponse.getString("status"));
                Log.i("Status", jsonResponse.getString("message"));
                Log.i("Status", jsonResponse.getString("debug"));
                TextView text1 = (TextView)findViewById(R.id.checkoutheading);
                text1.setVisibility(View.VISIBLE);
                TextView text = (TextView) findViewById(R.id.checkoutmessage);
                if (jsonResponse.getString("status").equals("SUCC")) {
                    text.setText( Html.fromHtml(getString(R.string.checkout_body1)));
                } else
                    text.setText(jsonResponse.getString("message")
                            + jsonResponse.getString("debug")); 

            }
        } catch (Exception ex) {

        }
    }


    private JSONObject encodeData(Settings setting) {
        JSONObject jobObject = new JSONObject();
        try {
            JSONObject jobject = new JSONObject();
            jobject.put("name", setting.getName());
            jobject.put("email", setting.getEmail());
            jobject.put("phone", setting.getPhone());
            jobject.put("school", setting.getSchool());
            jobject.put("major", setting.getMajor());

            jobObject.put("customer", jobject);
            JSONArray jobsarray = new JSONArray();
            for (Job job : JobsManager.JobsCartList) {
                JSONObject jobEntry = new JSONObject();
                jobEntry.put("jobtitle",job.getTitle());
                jobEntry.put("qty","1");
                jobsarray.put(jobEntry);
            }
            jobObject.put("orders", jobsarray);
        } catch (JSONException ex) {

        }
        return jobObject;
    }


    private Settings getSettings() {
        SettingsDBAccess settingsDBAccess = new SettingsDBAccess(
                DatabaseManager.getInstance());

        Settings setting = settingsDBAccess.getSetting();
        if (setting==null){
                startActivityForResult((new Intent(this,SettingsActivity.class)),Utils
                        .getDefaultRequestCode());
        }
        return setting;
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        Settings setting = new SettingsDBAccess(
                DatabaseManager.getInstance()).getSetting();
        if(setting!=null){
            JSONObject jobObject = encodeData(setting);
            sendDataToServer(jobObject);
        }

    }
/*  private class DataProcess extends AsyncTask {
        @Override
        protected void onPostExecute(Object result) {

        }

        @Override
        protected Object doInBackground(Object... arg0) {
            processDataandsend();
            return null;
        }

        private void processDataandsend() {
            Settings setting = getSettings();

            if(setting!=null){
                TextView text2 = (TextView)findViewById(R.id.checkoutheading);
                text2.setVisibility(View.GONE);
                Button homeButton = (Button)findViewById(R.id.gohome);
                homeButton.setVisibility(View.GONE);
            JSONObject jobObject =encodeData(setting);
            sendDataToServer(jobObject);

        }
    }

    } */
}
  • 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-27T18:49:13+00:00Added an answer on May 27, 2026 at 6:49 pm

    You should not perform HTTP-work on the UI-thread. Instead use AsyncTask

    In your AsyncTask you are only allowed to update the UI in two places:

      @Override
    protected void onPreExecute() 
    TextView.setText("Beginning HTTP-work..Please wait");
    {
    

    and

    @Override
    protected void onPostExecute(Void v) {
    TextView.setText("Done..SUCCESS!");
    }
    

    Use these two to update the UI before and after the HTTP-work has been done.

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

Sidebar

Related Questions

Hei. I am using the POST method for sending some information from a JSP
I have some WCF methods that are used to transmit information from a server
I'm sending some data to an external URL using Curl. The server sends me
Is there some way when sending this message to specify that I rather have
I'm writing an application which uses ASP.NET MVC with JSON.NET as the server, sending
Ok, I'm trying to send a STRUCT from a legacy C++ application to a
Can anyone tell me the best way to send some xml data from one
On our mailing application we are sending emails with the following header: FROM: marketing@customer.com
I am trying to get a Android device to send some information to a
I'm trying to save some information from a user that is saved on the

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.