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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:42:57+00:00 2026-06-06T12:42:57+00:00

I have to update different server data which takes huge time. I have to

  • 0

I have to update different server data which takes huge time. I have to update the data on conditions. When I am running for loop, it’s stuck the device for a minute. I want to do through handler else any other option (which I can’t think). currently I am doing as:

for(int i=0;i>10;i++)
{
if(i==0)
handler.post(runable-1);//Different server data
if(i==1)
handler.post(runable-2);//different server data
if(i==2)
handler.post(runable-3);//different server data
...
}

How could I do? Also I have to show to user that which runnable is loading data…
Please help. Thanks

  • 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-06T12:42:58+00:00Added an answer on June 6, 2026 at 12:42 pm

    What you probably want is AsyncTask. In your Activity class add

    class UpdateServerTask extends AsyncTask<Void, Void, Void> {
        private Object obj = null;
        private ProgressDialog dlg;
    
        @Override
        protected voide onPreExecute() {
            dlg = ProgressDialog.show (MyActivity.this, "", "Please wait, updating server...", true, false);     
        }
    
        @Override
        protected Void doInBackground(Void... params) {
            for(int i=0; i<10; i++) {
                switch(i) {
                    case 0: ...;
                            break;
                    case 1: ...;
                            break;
                    ...
                }
            }
        }
    
        protected void onPostExecute(Void result) {
    
            dlg.dismiss();
        }
    }
    

    And then, when you need to do the update:

    new UpdateServerTask().execute(null);
    

    Read up more on AsyncTask.

    Also, note that your for loop is not correct it should be <10 and not >10. Finally, I suggest you use switch case instead of if-else if-else construct.

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

Sidebar

Related Questions

I have a SQL Server 2008 database which contains data that I need to
I have to migrate existing data which is in SQL Server 2000 to SQL
I have 2 processes running in different machines which are communicating via TCP sockets.
I have a table which is update has some fields with repeating data. I
I have a list of items that I need to update on different intervals.
Let say I have a screen name ITEM thats performs different actions: Save, Update,
I have and Update Panel with a Grid inside of it. The grid's data
I have a data access layer which returns DataSets/DataTables by executing Stored Procedure. Everything
I have a Service downloading data every second from a web server (This Service
I have a custom Android ContentProvider which stores and retrieves data from a SQLite

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.