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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:05:41+00:00 2026-05-24T16:05:41+00:00

I think I might be on the wrong track here so I’m posting this

  • 0

I think I might be on the wrong track here so I’m posting this to find out.

I’m developing an android app that uses a number of rest-service requests to load its data.

I arranged my code following the n-tier pattern: domain layer (domain) / webservice access layer (dal) / business logic layer (service) / ui layer (ui)

From my activity I start an AsyncTask to load the items from the service layer. While the items are loading I show a progress dialog with a continious looping circle icon. This isn’t very user friendly, so I would like to display progress in stead via a progress indicator.

I can easily alter my dal so that it first gets a list of id’s of the items to fetch, and then fetches them one at a time, in stead of in bulk. This way I could report progress to the user, while updating the ui everytime a new item (or 2 or more) is loaded.

The problem is that I don’t know how to go about this. All the examples of AsyncTask work on the principle that everything happens within a class that inherits AsyncTask and this has to be executed from the ui thread.

Is there anyone who can provide a short code example on how I should define my AsyncTask class, and how I would be able to report progress from within the data access layer to the UI?

If I put all the code in the ui, there would be no problem, but that’s not very good practice imo.

Code example of what I want to do:

Somewhere in MainApplication I keep a list of orders:

public List<Order> orders = null;

My activity calls the AsyncTask and starts it:

OrderActivity.java

public void loadOrdersAsync() {
    // Create async task instance
    OrderLoaderAsyncTask loader = new OrderLoaderAsyncTask();

    // Start loading
    loader.doInBackground();
}

OrderLoadAsyncTask.java

public class OrderLoaderAsyncTask  extends AsyncTask {
    @Override
    public Integer doInBackground(Context.... params) {
        OrderService service = new OrderService();
        MainApplication.orders = service.getAll();
    }

    @Override
    public void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);

        // Update progress bar
        updateProgressBar(values);
    }
}

OrderService.java

public class OrderService {
    public List<Order> getAll() {
        // Check to see if we have a cached version
        // If we don't, we fetch the orders from REST webservice
        OrderRepository repository = new OrderRepository();

        // Get list of ID's to fetch
        List<Integer> ids = new ArrayList<Integer>;
        List<Order> orders = new ArrayList<Order>;
        ids = repository.getIDs();

        // For each id, fetch order from webservice
        for (Integer id : ids) {
            Order order = repository.getOneById(id);

            orders.add(order);

            // Report progress, but how?
        }

        return orders;
    }
}

Now in my service I can keep track of the progress, but how do I report this progress to the UI without moving the logic to build the orderslist to my AsyncTask class? How do I report progress from within my service layer? Or even from within my repository layer?

  • 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-24T16:05:42+00:00Added an answer on May 24, 2026 at 4:05 pm

    I don’t see a way of doing that with precision, REST services are kind of request-reply, you’ll receive data only after its all loaded in data layer inside REST server.

    I’ll do it with a progress bar, updating each 500mS with a Timer. Just have in mind that Timer fires another thread, so you need to update UI inside a runOnUiThread() method of your activity.

    Example code:

    public class myActivity extends Activity {
    
        private Timer myTimer;
    
        @Override
        public void onCreate(Bundle b) {
            super.onCreate(b);
            setContentView(R.layout.main);
    
            myTimer = new Timer();
            myTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    TimerMethod();
                }
    
            }, 0, 500);  // 500mS starting with no delay
        }
    
        private void TimerMethod()
        {
                // this runs each time Timer fires
            this.runOnUiThread(Timer_Tick);
        }
    
        private Runnable Timer_Tick = new Runnable() {
            public void run() {
    
                // do something with my progress bar
            UpdateMyProgressBar();
    
            }
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I might be approaching this in the wrong way, so I would
I have a large mysql table that I think might be using the wrong
I'm currently developing an app that uses Core Data. I'm using two stores/configurations, one
I can't see what I'm doing wrong. I think it might be one of
The major difference between a thing that might go wrong and a thing that
I think it might have been asked before but i was unable to find
I think this might be a problem with the theme I'm using ( Nitobe
I don't think this has been asked before on this site, but I might
I think I might be using the wrong words, however I am looking for
I´m not a coder, so I might ask wrong :) Was using this little

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.