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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:17:45+00:00 2026-05-16T23:17:45+00:00

I am requesting information from a web service in my android app. The web

  • 0

I am requesting information from a web service in my android app. The web service returns a list of items, each item having a base64 image and some info

First method: simply access the web service and get the result. This means freeze of UI until data is downloaded. Not a good solution

Second method: put the data download in a thread, and display a progress bar with a message.

 private void StartGettingData()
    {
        viewInfo = new Runnable(){
            public void run() {
                getData(); //from the web service
            }
        };
        Thread thread =  new Thread(null, viewInfo, "MagentoBackground");
        thread.start();
        progressDialog = ProgressDialog.show(TracksListActivity.this,    
              "Please wait...", "Retrieving data from WEB...", true);
    }

    private void getData(){
    {
      get data from web service into a list and then 

      runOnUiThread(returnRes);
    }

     private Runnable returnRes = new Runnable() {

     public void run() {
         populate the listview adapter with info from the web service result list and

         progressDialog.dismiss();
         generalTrackInfoAdapter.notifyDataSetChanged();
     }
 };

This shows a nice loading image and the message. The user will have to wait until all the download is complete. I don’t know how to cancel the getdata() thread.

Third method: I would like to have something like, the user presses a button to get data, a thread downloads item by item from the web service and immediate shows it in the list. The use can always cancel the request with a button press.

But, how to do this ? Or is there another way ?

  • 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-16T23:17:45+00:00Added an answer on May 16, 2026 at 11:17 pm

    You can use AsyncTask for threading, basics: painless threading, example:Multithreading For Performance(image downloader).

    Because using the class thread or the interface runnable your code becomes more complicated and more difficult to read. It becomes even worse when you implement complex operations that require frequent UI updates.

    The goal of AsyncTask is to take care of thread management for you.

    The basic structure is:

    public class DownloaderTask extends AsyncTask<String, String, String>{
    
        protected void onPreExecute(){}
    
        protected String doInBackground(String....args){
            //do something in background
        }
    
        protected void onProgressUpdate(String str){}
    
        protected void onPostExecute(String result){
             //..update ui
        }
    }
    

    …to start your task e.g.:

    public void onClick(View v){
         new DownloaderTask().execute("param");
    }
    
    • The method doInBackground() executes
      automatically on a worker thread

    • onPreExecute(), onPostExecute() and
      onProgressUpdate() are all invoked on
      the UI thread

    • The value returned by
      doInBackground() is sent to
      onPostExecute()

    • You can call publishProgress() at
      anytime in doInBackground() to
      execute onProgressUpdate() on the UI
      thread

    • You can cancel the task at any time,
      from any thread

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

Sidebar

Related Questions

thanks for any assistance. I'm creating a wcf web service for an external client.
When requesting hardware for a WebLogic server, what hardware would best improve its performance?
I often have customer requesting changing properties, like the version history setting on all
If I have a resource that a requesting client doesn't have access to but
I need code in Perl for requesting and parsing ATOM and RSS feeds. Is
There are many techniques to enforce strong passwords on website: Requesting that passwords pass
I am working on an ASP.NET page that we, in code impersonate the requesting
We have a custom written on-line job application... application. HR is requesting a skill
I am developing a Java web application that bases it behavior through large XML
OK so to set and read variables from the current session String Myvar =(string)

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.