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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:40:49+00:00 2026-06-18T08:40:49+00:00

i have the following code to load a file from my website class DownloadTT4FileTask

  • 0

i have the following code to load a file from my website

class DownloadTT4FileTask extends AsyncTask<String, String, String> {

                    private Context mContext;
                    private String  mFilename;
                    private ProgressDialog progressDialog;
                    String  retString="";

                    public DownloadTT4FileTask(Context context, String filename) {
                        mContext=context;
                        mFilename=filename;
                    }

                    @Override
                    protected void onPreExecute() {
                        Log.d("DownloadTT4FileTask", "onPreExecute");
                        progressDialog = ProgressDialog.show(mContext, mFilename, "Loading. Please wait...");
                    }

                    protected String doInBackground(String... args) {

                        URL url;
                        try {
                            url = new URL(args[0]);
                            java.net.URLConnection con = url.openConnection();
                            con.connect();
                            //Log.d("DownloadTT4FileTask", "con.connect ok ");

                            java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream()));
                            String line;
                            for (; (line = in.readLine()) != null; ) {
                                // just read the line and save it
                                retString += line+"\n";
                            }   

                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                        return retString;
                    }

                    protected void onPostExecute(String result) {
                        Log.d("DownloadTT4FileTask", "onPreExecute");
                        progressDialog.dismiss();
                    }
                };
                // loading from website
                filename = "http://2112design.com/tabs/"+band+"/"+song+".tt4";
                String fileContents = new DownloadTT4FileTask(context, filename).execute(filename).get(15L, TimeUnit.SECONDS);

                br = new BufferedReader(new StringReader(fileContents));

it loads fine (about 5 secs to load) but the progress dialog is a bit off. it doesn’t show up on the screen at the start of the download. it briefly flashes on screen at the end of the task.

i’ve seen many examples of how to use this and it looks like this is pretty normal code.

maybe the context is the issue? i get that from an onChildClick that running in a fragment which isn’t the main activity. i tried using the main activity context but that just crashed.

    @Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    Globals.mDoc.OpenTT4Document(parent.getContext(), band, song, mRemoteFilesThis==null ? Doc.SDCARD : Doc.WEBSITE);

    return false;
}

any ideas? 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-18T08:40:51+00:00Added an answer on June 18, 2026 at 8:40 am

    as Doc says about AsyncTask.get() :

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

    currently you are calling AsyncTask.get() on main UI thread and progress dialog not appeared . you will need to start AsyncTask without calling get() method as :

    new DownloadTT4FileTask(context, filename).execute(filename);
    

    and update UI after doInBackground completed inside onPostExecute as :

                    protected void onPostExecute(String result) {
                        Log.d("DownloadTT4FileTask", "onPreExecute");
                        progressDialog.dismiss();
                         // get result here
                        br = new BufferedReader(new StringReader(result));
                    }
    

    EDIT :

    if you want to call get method of AsyncTask then use a Thread to get result back and avoid freezing of UI as :

    new Thread(new Runnable() {
      public void run() {
         try {
                Your_Activity.this.runOnUiThread(new Runnable() {
                public void run() {
    
                   progressDialog = ProgressDialog.show(Your_Activity.this, 
                     mFilename, "Loading. Please wait...");
                }
               });
                  // start AsyncTask here
                  String fileContents = new DownloadTT4FileTask(context, filename)
                                         .execute(filename).get(15L, TimeUnit.SECONDS);
    
                  Your_Activity.this.runOnUiThread(new Runnable() {
                     public void run() {
                        // update UI elements here
                         br = new BufferedReader(new StringReader(fileContents));
                           progressDialog.dismiss();
                      }
                  });
              } catch (InterruptedException e) {
               // TODO Auto-generated catch block
                e.printStackTrace();
              } catch (ExecutionException e) {
                 // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (TimeoutException e) {
                        // TODO Auto-generated catch block
                   e.printStackTrace();
              }
           }
     }).start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following piece of code which tries to load an XML file from
I have the following code in my application to load some data from my
I have the following code that read input from txt file as follow Paris,Juli,5,3,6
I have the following R code to load xts timeseries from multiple files and
I have the following code that loads a plist file from the resource folder
I have the following code in my file to load a div with HTML
i have the following code to try and load a local html page in
I have the following code - it is used to load a drop down
I have the following code: $(function () { $(#ARO).load('/DA.aspx?section=ARO #ARO', function() { DoSomething1(); });
I have the following code, which I want to load values on a selection

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.