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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:02:50+00:00 2026-06-18T09:02:50+00:00

I am building an android app in which I need to download a pdf

  • 0

I am building an android app in which I need to download a pdf and then view it. I have the downloading and viewing code working fine. I decided to use an Asynctask to download and show the progress. However, when it is launched, the system appears to have frozen and the dialog box doesn’t come up until after the file has been downloaded. This is my onClick code:

public void onClick(View v) {
    DownloadFile downloadFile = new DownloadFile();
    downloadFile.execute(
            "http://store.aqa.org.uk/qual/newgcse/pdf/AQA-4130-W-SP.PDF",
            "userguide.pdf");
    try {
        downloadFile.get();
        viewPDF(getExternalFilesDir(null) + "/userguide.pdf");
    } catch (Exception e) {
    }
}

Any idea how I could resolve this.

I have considered that I can put the viewPdf in the onPostExecute method, but this method is specifically for downloading files and this is a special case with which the pdf has to be viewed.

Thanks in advance

Edit: I solved my problem.

I added a parameter in which I would specify the of the request. This gets included in result and dependent upon it, it might get shown or not. Thanks for all the help

  • 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-18T09:02:52+00:00Added an answer on June 18, 2026 at 9:02 am

    as doc says

    AsyncTask.html.get() :

    Waits if necessary for at most the given time for the computation to
    complete, and then retrieves its result.

    means if you call get method for getting result from AsyncTask this will make wait in UI thread until control back from AsyncTask doInBackground method.

    you can solve current issue by passing Current Activity Context to DownloadFile for Accessing method’s from Activity to onPostExecute method as :

    private class DownloadFile extends AsyncTask<String, Void, String> {
    
    Context context;
    
    public DownloadFile(Context context){
    this.context=context;
    }
     @Override
       protected void onPreExecute() {
       }
          @Override
          protected String doInBackground(String... params) {
                // put your PDf downloading related code here
                return null;
          }      
    
          @Override
          protected void onPostExecute(String result) {
    
            // Access Activity method here using context;
             context.viewPDF(getExternalFilesDir(null) + "/userguide.pdf");      
          }
    
    }
    

    and execute DownloadFile on Button click as from Activity :

    public void onClick(View v) {
        DownloadFile downloadFile = new DownloadFile(Current_Activity.this);
        downloadFile.execute(
           "http://store.aqa.org.uk/qual/newgcse/pdf/AQA-4130-W-SP.PDF",
           "userguide.pdf");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an Android app and I need to have two different themes for
I am building an android app for which I need to check the sync
I am building an android app in which I have to add a background
I am building an android app which will download some data and display it
I am building an android app in which I need to show the list
I’m building an android app and I have a xml file which is my
Problem: I am building Android app in Eclipse which uses shared lib libgstreamer-0.10.so (GStreamer-android
I'm building a fairly simple Android app (sdk revision 14: ICS) which allows users
I am building an android app, and I want to be able to have
I am building an Android app using phoneGap and I have successfully added the

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.