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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:29:42+00:00 2026-05-22T12:29:42+00:00

i am downloading data from website using asynctask and my code for async task

  • 0

i am downloading data from website using asynctask and
my code for async task is below

public class getSyncTaskInBackground extends AsyncTask<Void, Void, Void>{
    @Override
    protected Void doInBackground(Void... params) {
        getSynchronizeTask();
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        if(progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
        displaySynchronizetask();
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        progressDialog = ProgressDialog.show(synchronize.this, "Tasks are synchroning...", "Please wait...");
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
        if(progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }

}

this thread takes more time to complete task
so if i want to cancel this thread in between of process then i had write this code of back button pressed
or if progressbar is already dismiss then i want to close activity by calling finish();
my code for back button is as below

@Override
public void onBackPressed() { 
    syncThread.cancel(true); //syncThread is the object of getSyncTaskInBackground
if(progressDialog != null && progressDialog.isShowing()) {
    progressDialog.dismiss();
} else {
    finish();   
}
}

Now when i pressed back button then the progressdialog is not dismiss
is any mistake in mycode ? is any way to complete my need ?
please help me

  • 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-22T12:29:43+00:00Added an answer on May 22, 2026 at 12:29 pm

    Hi
    You might want to call
    setCancelable with true on your progressDialog instance :
    http://developer.android.com/reference/android/app/Dialog.html#setCancelable(boolean)

    If you want an event on the cancelation of your progressDialog
    you can set an onCancelListener
    http://developer.android.com/reference/android/app/Dialog.html#setOnCancelListener(android.content.DialogInterface.OnCancelListener)

    hope this helps

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

Sidebar

Related Questions

I am downloading a text string from a web service into an RBuf8 using
I had an application that was downloading a .CSV file from a password-protected website
I'm downloading 6kB of data from a test instrument connected via TCP socket. I'm
I have a doubt regarding downloading data from a web service. One way is
After downloading all .NET framework symbols and sources using NetMassDownloader , is it possible
After downloading files from a remote UNIX FTP server, you want to verify that
I'm downloading an entire directory from a web server. It works OK, but I
I'm downloading some images from a service that doesn't always include a content-type and
I am downloading a JPEG image from a server and assigning it to an
I am trying to post some data and get some data back from a

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.