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

  • Home
  • SEARCH
  • 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 6155227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:24:04+00:00 2026-05-23T20:24:04+00:00

One of my activities make a http request to a webservice to get some

  • 0

One of my activities make a http request to a webservice to get some weather data when I start the application.

The issue that the activity will take 3-4 seconds to display because of the webservice request. ( Tested on actual device )

I know I m not doing this the right way. All I m doing is on the onCreate method, I m making the request , getting the xml back, parsing and displaying the data.

What is the best way to deal with webservice requests in Android so the application won’t display a white screen while the request is being made? Maybe some threads…….

I know this is not happening on other application I have in my device that make request to get live data.

Notes:

1) The xml I getting back is not that big ( 5 elements with 5 nested elements on each one).

2) I tried with the 3G network and Wifi but the response time is still the same.

sample code:

   @Override
    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.clock_weather);

   // this is where it is making the request and parsing the xml.
    WeatherSet set = getWeatherCondition("New York, NY");

    TextView currentWeather  = (TextView) findViewById(R.id.current_weather);
    currentWeather.setText("" + set.getWeatherCurrentCondition().getTempFahrenheit());

    TextView currentWeatherH  = (TextView) findViewById(R.id.current_weatherH);
    currentWeatherH.setText("H: " + set.getWeatherForecastConditions().get(0).getTempMaxFahrenheit());

    TextView currentWeatherL  = (TextView) findViewById(R.id.current_weatherL);
    currentWeatherL.setText("L: " + set.getWeatherForecastConditions().get(0).getTempMinFahrenheit());

    ImageView currentWeatherIcon  = (ImageView) findViewById(R.id.current_weather_icon);
    String imageUrl = set.getWeatherCurrentCondition().getIconURL();
    Drawable bitmapDrawable = getImageBitmap(imageUrl);
    currentWeatherIcon.setImageDrawable(bitmapDrawable); 

    setForecastInfo(set, R.id.day1, R.id.day1_icon, R.id.day1_temp, 1  );   
    setForecastInfo(set, R.id.day2, R.id.day2_icon, R.id.day2_temp, 2  );   
    setForecastInfo(set, R.id.day3, R.id.day3_icon, R.id.day3_temp, 3 );    
    setForecastInfo(set, R.id.day4, R.id.day4_icon, R.id.day4_temp, 4  );
}
  • 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-23T20:24:04+00:00Added an answer on May 23, 2026 at 8:24 pm

    The time for your response is unpredictable – your network connection can be very poor and take seconds to transfer a few bytes. So the correct way to do this ( as you propose ) is to use thread. In our case android provides very useful class to handle this situations – AsynTask. After you read the docs you will notice that it has 3 very powerful methods that can help you

    1. onPreExecute runs in the ui thread – very helpful to show some spinner or some progress indicator to show the user that you are doing some work in background
    2. doInBackground runs in background – do your background work here
    3. onPostExecute runs in the ui thread– when your are done with your background work hide the progress and update the gui with the newly received data.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to make a custom ContentProvider so that more than one application (activity?)
I want to make an application that user will login in one activity with
I wrote application that contain 2 activities. In the first one - i need
I want to make some data available between some activities, just like a shopping
This is my situation. I have two activities: ONE and TWO. In TWO activity
I have two Activities along with one Application class, and whenever I call my
I have one class called Global and two other activities. In each activity I
I have a design of activities like this I have one main activity and
I have a one main Workflow which calls several activities asynchronously. Some of the
I've got two Activities. In one I calculate some things and therefore I have

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.