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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:19:33+00:00 2026-06-16T01:19:33+00:00

I am having two tasks running in doInBackground(). One task is reading data from

  • 0

I am having two tasks running in doInBackground(). One task is reading data from site and another task is parsing xml file from Url and set image in imageview. But i want to separate both tasks means once the reading from the site is completed , it should set text in textview. and after that xml parsing should start. So what can i do ?

Here is my code :

private class DownloadWebPageTask extends AsyncTask<String, Void, ArrayList<String>>
    {
        ProgressBar progressBar;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            progressBar = (ProgressBar)findViewById(R.id.showLoading);
            progressBar.bringToFront();         

        }

        @Override
        protected ArrayList<String> doInBackground(String... arg0)
        {
            String xml = null;

            ArrayList<String> lyricArtistArray = new ArrayList<String>();

                    //get lyrics - First task
            lyricsArray = SearchHelper.findLyrics(arg0[0],arg0[1]);
            lyricArtistArray.add(lyricsArray);

                //get image - Second task
            artistNameGlobal = arg0[1].toString();
            try
            {
                XMLParser parser= new XMLParser();
                String img;
                String t = arg0[1].replace(" ","%20");
                String url = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+t+"&api_key=mykey";
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                xml = EntityUtils.toString(httpEntity);
                Document doc = parser.getDomElement(xml);
                NodeList nl = doc.getElementsByTagName("artist");
                for(int i=0;i<1;i++)
                {
                    Element e = (Element)nl.item(i);
                    img = parser.getValue(e,"image");
                    System.out.print(img);
                    ImageView imageArtist = (ImageView) findViewById(R.id.artistImageView);
                    imageArtist.setImageBitmap(LoadImageFromURL(img));
                }               
            }
            catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }

            return lyricArtistArray;
        }

        @Override
        protected void onPostExecute(ArrayList<String> lyricArtistArray)
        {
            progressBar.setVisibility(View.GONE);

            tvMain.setTextSize(fontSize);
            tvMain.setTextColor(FontColor);
            if(!FontStyle.equals("None"))
            {
                String s = FontStyle.concat(".ttf");
                String s1 = "fonts/"+s;
                Typeface tf=Typeface.createFromAsset(getAssets(),s1);
                tvMain.setTypeface(tf); 
            }

            tvMain.setText(Html.fromHtml(lyricArtistArray.get(0).toString()));
            tvMain.setMovementMethod(new ScrollingMovementMethod());                    
            tvMain.setSelected(true);       
        }
    }

How should i handle these two tasks ? Please suggest me some solution so that it takes minimum time. Please reply me fast. Thanx in advance.

  • 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-16T01:19:35+00:00Added an answer on June 16, 2026 at 1:19 am

    A couple of approaches come to mind. The first is to implement onProgressUpdate(Progress...) passing a String and set the value of the TextView within this method. You would then call updateProgress after your download is complete, but before the parse starts. This would be the minimum amount of work on you part to get this working.

    The other route is to create a new AsyncTask with just the parse code in it. The first AsyncTask (which would now just perform the download) will set the TextView content and start the parsing AsyncTask in its onPostExecute.

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

Sidebar

Related Questions

I have two lists. First one is a list of Tasks pulled from an
I am writing a basic file dump from one database to another. I am
forum member I need one help from you all. I am having two POJO
One of the problems I have come across having complex tasks on the browser
Concurrency is having two tasks run in parallel on separate threads. However, asynchronous methods
I have a rails application running over Postgres. I have two servers: one for
I have a page that pulls together aggregate data from two different tables. I
I've been having some issues with a couple of tasks I'm running. I have
I've been having some trouble trying to send a file from a server to
Having two forms, each in it's own jQuery UI tab, how can I post

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.