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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:36:54+00:00 2026-05-20T09:36:54+00:00

I have a function which can vary in the time it takes to finish.

  • 0

I have a function which can vary in the time it takes to finish. I would like to display a progress dialog whilst this function is operating.

I am aware that you can use a ‘Thread’ to achieve this. Can someone point me in the right direction for doing this ?

EDIT:
Here is the code I am using:

private class LongOperation extends AsyncTask<String, Void, String> 
{
    ProgressDialog dialog;
    public Context context;
    @Override
    protected String doInBackground(String... params) {
        if (!dialog.isShowing())
            dialog.show(); // Just in case
        return null;
    }

    /* (non-Javadoc)
     * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
     */
    @Override
    protected void onPostExecute(String result) {
        dialog.dismiss();
    }

    /* (non-Javadoc)
     * @see android.os.AsyncTask#onPreExecute()
     */
    @Override
    protected void onPreExecute() 
    {
        dialog = ProgressDialog.show(context, "Working", "Getting amenity information", true);
    }

    /* (non-Javadoc)
     * @see android.os.AsyncTask#onProgressUpdate(Progress[])
     */
    @Override
    protected void onProgressUpdate(Void... values) {
      // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
     }
}

this is the Asnyc class. The user selects an option from the menu, and this is then executed:

longOperation.execute(""); // Start Async Task

GetAmenities(Trails.UserLocation); // Long function operation
  • 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-20T09:36:54+00:00Added an answer on May 20, 2026 at 9:36 am

    You should use AsyncTask for this purpose. See Android developers website and How to use AsyncTask.

    Some sample code:

    private class LongRunningTask extends AsyncTask<Void, Boolean, Boolean> {
    
        private ProgressDialog progress;
    
        protected void onPreExecute() {
            progress = ProgressDialog.show(yourContext, "Title", "Text");
        }
    
        @Override
        protected Boolean doInBackground(Void... params) {
            return true;
        }
    
        protected void onPostExecute(Boolean result) {
            if(result) {
               progress.dismiss();
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function which creates an array of pointers. The function which allocates
I have 9 boxes (div) on a page. I am able to move them
Comments on my answer here have made me think about how one might implement
So basically the title sounds way fancier than the actual question. I am writing
I'm implementing a class that talks to a motor controller over a USB device.
I am started working on resume retrieval(document) component based on lucene.net engine. It works
Fairly new to jQuery and JavaScript in general. I mocked up an example of
In the following code, whatever is passed as retval is evaluated as given for
I read that both multiple returns and multiple goto statements are bad programming practice.
I need a way to take a block of HTML code and make all

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.