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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:12:15+00:00 2026-05-16T01:12:15+00:00

I have an application that is performing HTTP Requests (specifically calling the FogBugz API)

  • 0

I have an application that is performing HTTP Requests (specifically calling the FogBugz API) when the user clicks certain buttons. Right now, I am just creating a service when the application starts, and then calling different methods in that service to complete requests. However, when I do this, there is the usual hang in the UI thread. I have looked at AsyncTask, but am not sure it will do what I want to accomplish. Because I need to instantly parse the XML that the HTTP Request returns, I need to have a process that is able to return this data to the UI thread. Will ASyncTask be able to accomplish this, or is there some other way?

    public static InputStream makeRequest(String httpRequest)
    {
        In a separate thread, run HTTP Request, get back and process, return inputstream
    }

This method is called by several others to perform HttpRequests. Once the inputstream is returned, the other methods parse for specific information.

  • 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-16T01:12:16+00:00Added an answer on May 16, 2026 at 1:12 am

    The simplest way to do it would just be to do something like

    //Body of your click handler
    Thread thread = new Thread(new Runnable(){
      @Override
      public void run(){
        //code to do the HTTP request
      }
    });
    thread.start();
    

    That will cause the code inside the run() method to execute in a new thread of execution. You can look into an async task if you like although I’ve personally never used it. This is a quick and simple way to get things done.

    With regards to passing information back, I would use a Handler object which effectively allows you to set up a message queue for a given thread and pass messages to it which cause the execution of specific code. The reason you need to do this is because Android will not let any thread other than the UI thread update the actual UI.

    Does that address your question? I know my first pass didn’t fully address all of your issues.

    Edit Basically, what you do is define a handler object in your Activity like

    private Handler handler_ = new Handler(){
        @Override
        public void handleMessage(Message msg){
    
        }
    
    };
    

    You also create static int constants that help tell the handler what to do. You basically use those to allow for several different types of messages to be passed to one instance of a handler. If there is only going to be one message that is passed back, then you don’t have to worry about that.

    For example

    private static final int UPDATE_UI = 1;
    

    To send a message to the handler you call

    handler_.sendMessage(Message.obtain(handler_, UPDATE_UI, inputStreamInstance));
    

    From the handler:

    private Handler handler_ = new Handler(){
        @Override
    public void handleMessage(Message msg){
        switch(msg.what){
                case UPDATE_UI:
                InputStream is = (InputStream)msg.obj;
                //do what you need to with the InputStream
                break;
            }
        }
    
    };
    

    Alternatively, where the inputStreamInstance is added to the Message object, you can pass any object you like so if you wanted to parse it into some kind of container object or something like that, you could do that as well. Just cast it back to that object from within the handler.

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

Sidebar

Related Questions

I have a web application that stores a lot of user generated files. Currently
I have android application that I need to debug using eclipse. When I right
I have a Java application that is performing some realtime image processing, with the
I have a simple console application that outputs a menu and waits for user
I am performing HTTP Basic Authentication in my Android application. Recently, however, I have
I have an application that is performing an SQL backup of a database over
I have an Cocoa Application (Mac OS X SDK 10.7) that is performing some
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in

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.