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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:56:36+00:00 2026-06-13T09:56:36+00:00

I am writing an android application where all my data is expose using web

  • 0

I am writing an android application where all my data is expose using web service. I am writing a wrapper class to fetch data from the services called DataManager.

public class DataManager{

public DataManager (){}


public String getValue ()
{
    HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet ("some url");

    try 
    {
        HttpResponse response = client.execute(get);
        if (response.getStatusLine ().getStatusCode() == 200)
        {
            HttpEntity entity = response.getEntity ();
            String result = EntityUtils.toString(entity);
            return result;
        }
    } 
    catch (ClientProtocolException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (IOException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

}

When I call this method a RuntimeException is generated on the UI thread. How can I refactor this
code and fetch the values from the webservice and return these values asynchronously. [NOTE] I am writing this for some team members so they can use it to get data from the service so I want it to be has easy has possible for them to use.

  • 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-13T09:56:37+00:00Added an answer on June 13, 2026 at 9:56 am

    Use AsyncTask or IntentService. Doing networking (and in general lengthy operations) on UI thread is no-no on Android.

    Here you got with AsyncTask fundamentals and some tutorials
    And here you got with IntentService fundamentals and tutorials

    I’d use AsyncTask myself (IntentService’s jobs are queued), but be aware about change in the way it is handled in newer APIs. Not a big deal (just a few more code lines), though

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

Sidebar

Related Questions

I'm writing an android application using eclipse. I have a main activity called MenuActivity
All, I'm writing a native application for Android and i'm stuck trying to acquire
I am writing an Android application which can enable and disable the Network Data
I'm writing an Android application, which uses AccountManager to get the token. From an
I'm writing an android application that maintains a lot of state data...some of it
I'm using a book called Android Wireless Application Development 2nd edition 2009 (L.Darcey &
I'm writing code for an Android application that is supposed to take data, package
I'm writing an application that needs to receive data from a socket every 10
I am writing an HTML5 application that is gathering data from a few different
I am writing an android application that needs to display street data only, stuff

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.