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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:49:59+00:00 2026-05-26T01:49:59+00:00

EDIT: If I do not use the progress at all, just showing the dialog,

  • 0

EDIT: If I do not use the progress at all, just showing the dialog, then everything works without any problems. But if i add progress, then dialog doesn’t close(method onPostExecute() is not fired).


onPostExecute method is not executed. Where do I have a mistake? (Same result on emulator and on the device)
I am also not sure if I should use Override notation for these methods

This is the rough solution for now. It works every time, but is not the proper and not the nice one.
What I am doing:
* I start a child activity using tabgroupactivity
* Then i navigate to another activity in the child activity, so it is a current child of a parent
* There is a webview, where I display information about one comment.. whatever
* There is a link in the content displayed by the webView
* when i click it, i start downloading the PDF file.

When the file is downloaded:

    while ((current = bis.read()) != -1) {
        read = read + current;
        baf.append((byte) current);
        Dialog.setProgress(read);

        if(Dialog.isShowing() && read+2*current>file_size){
            Dialog.dismiss();
            Dialog.cancel();
        }
    }

My Dialog object is disapeared, so if I try to call Dialog after the While loop, i just don’t get it. So what I did is that every time i get new buffer from website, i check if the dialog is still visible and if the current byte together with the amount of bytes read up to now are greater than the full size of the file, then I close the dialog in the while loop.
I tried using fileSize == read(amount of bytes), but it did not work, maybe they are not precisely mach each other when the file is downloaded

private class DownloadPDFFile extends AsyncTask<String, Integer, Void> {
    private ProgressDialog Dialog = new ProgressDialog(getParent());

    protected void onPreExecute() {
        Dialog.setMessage("Downloading PDF file..");
        Dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        Dialog.setCancelable(false);
        // Dialog.setMax(1000);
        Dialog.setProgress(0);
        Dialog.show();
    }

    protected Void doInBackground(String... urls) {
        File file=null;
        int file_size = 0;
        try {
            URL url = new URL(urls[0]);
            URLConnection urlConnection = url.openConnection();
            urlConnection.connect();
            file_size = urlConnection.getContentLength();
            Dialog.setMax(file_size);
        } catch (IOException e) {

        }

        try {
            URL url1 = new URL(urls[0]); // you can // link

            file = new File("skm_intern_pdf.pdf");

            URLConnection ucon = url1.openConnection();

            InputStream is = ucon.getInputStream();

            BufferedInputStream bis = new BufferedInputStream(is);

            ByteArrayBuffer baf = new ByteArrayBuffer(5000);
            int read = 0;
            int current = 0;
            while ((current = bis.read()) != -1) {
                read = read + current;
                baf.append((byte) current);
                Dialog.setProgress(read);

                if(Dialog.isShowing() && read+2*current>file_size){
                    Dialog.dismiss();
                    Dialog.cancel();
                }
            }

            FileOutputStream fos = openFileOutput("skm_pdf.pdf",
                    Context.MODE_WORLD_WRITEABLE);
            fos.write(baf.toByteArray());
            fos.flush();
            fos.close();

        } catch (IOException e) {

        }

        return null;
        }
  • 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-26T01:50:00+00:00Added an answer on May 26, 2026 at 1:50 am

    Is the parent of the AsyncTask cancelled/paused/destroyed before the AsyncTask finishes?

    If yes, the AsyncTask might recieve a cancel() which results in onPostExecute() never to be run. To verify this, try overriding onCancelled()-method and check if it is run.

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

Sidebar

Related Questions

I'm not sure what kind of terminology to use in this so please edit
Edit: This is not a conflict on the theoretical level but a conflict on
Edit: It's not a bug as Martin pointed out. I'm just crossing the daylight
Wondering if there's any not-too-hard way to edit non-form text in html 4. I
I have read through the solutions to similar problems, but they all seem to
EDIT: It is not a listbox. My mistake. It is a list view. I
[edit] I am NOT using jquery in this app. Looking for a way to
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
If I do not create an Edit->Copy menu item and assign it the shortcut
If not, what are the significant differences? Edit: Daren Thomas asks: which ones? I

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.