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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:17:19+00:00 2026-06-18T05:17:19+00:00

I have an asynctask that I am using to parse JSON and XML data

  • 0

I have an asynctask that I am using to parse JSON and XML data during my ocCreate method. The problem is that the Async Task only finishes it’s “do in background” work once out of every ten times. When it fails to complete it’s background work, the app crashes due to variables the weren’t instantiated in the background process and are referenced in post-execute. This is very strange, because when the AsyncTask finishes it background work everythig works fine. Any help is greatly appreciated

My Code

 private class LoadingData extends AsyncTask<String, Integer, String> {

    @Override
    protected String doInBackground(String... sUrl) {

            //TWITTER
            //Parses Twitter XML with no problem...

publishProgress(15,1);

//SPOT GOLD AND SILVER

                try{
                    GoldSpotPriceReader.feed = "http://feed43.com/437361835043234.xml";//Gold
                    GoldSpotPriceReader.getLatestRssFeed();
                    livespotgold=GoldSpotPriceReader.spotprice;
                    storedspotgold=livespotgold;

                    SilverSpotPriceReader.feed = "http://feed43.com/824383110654537.xml";//Silver
                    SilverSpotPriceReader.getLatestRssFeed();
                    livespotsilver=SilverSpotPriceReader.spotprice;
                    storedspotsilver=livespotsilver;
                }catch(NumberFormatException e){    
                    Log.e("Spot Price Initial", "Spot Price Format Error "+e.toString());
                } 
//AsyncTask Usually Ends Here For No Particular Reason.
    //And doesn't finish background work...                 
publishProgress(30,2);

//More background work...           

 @Override
    protected void onPreExecute() {
        super.onPreExecute();
        dialog = new ProgressDialog (MyActivity.this);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        //dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setMessage("Fetching Latest News");          
        dialog.setIndeterminate(false);
        dialog.setMax(100);
        dialog.setProgress(0);
        dialog.show();

        finddealer = (MapView) findViewById(R.id.mvFindDealer);
        finddealer.setBuiltInZoomControls(true);

        Touchy tango = new Touchy();
        overlayList = finddealer.getOverlays();
        overlayList.add(tango);
        compass = new MyLocationOverlay(MyActivity.this, finddealer);
        overlayList.add(compass);
        controller = finddealer.getController();
        controller.setZoom(11);

        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(lm.GPS_PROVIDER, 300000, 5000, MyActivity.this);
        crit = new Criteria();
        towers = lm.getBestProvider(crit, false);
        location = lm.getLastKnownLocation(lm.GPS_PROVIDER);

        delta = getResources().getDrawable(R.drawable.map_pin_48);
        zulu = getResources().getDrawable(R.drawable.ic_launcher);
    }

@Override
    protected void onProgressUpdate(Integer... progress) {
        super.onProgressUpdate(progress);
        dialog.setProgress(progress[0]);
        switch (progress[1])
        {
            case 1:
                dialog.setMessage("Acquiring  Prices...");
                break;
            case 2:
                dialog.setMessage("Acquiring  Rates...");
                break;
            case 3:
                dialog.setMessage("Acquiring More Rates...");
                break;
            case 4:
                dialog.setMessage("Pinpointing Your Location...");
                break;
            case 5:
                dialog.setMessage("Locating Nearest  Dealers...");
                break;
            case 6:
                dialog.setMessage("Calculating Shortest Routes...");
                break;
            case 7:
                dialog.setMessage("Mapping  Dealers...");
                break;
            case 8:
                dialog.setMessage("Finalizing...");
                break;
        }
    }               

  @Override     
    protected void onPostExecute(String result) {       
        super.onPostExecute(result);
        dialog.setProgress(100);
        dialog.setMessage("Load Complete.");
        dialog.dismiss();

 //Other UIthread variables...
}
  • 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-18T05:17:20+00:00Added an answer on June 18, 2026 at 5:17 am

    I have had similar situation before with my AsyncTask. the problem was that I was catching an exception and trying to throw a toast without a handler and runnable. So make sure you not trying to do anything on the UIThread within do-in-background process.

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

Sidebar

Related Questions

In my app I have a background task (using AsyncTask) that downloads stuff from
I have a method that is executed using asyncTask with a progressdialog. After this
I have a long running Async Task that sends some data to my server
My goal is to have an AsyncTask that can execute multiple times (one task
I have a class that extends AsyncTask. In the doInBackground() method, I connect to
I have an AsyncTask that handles a rather long download, using HttpClient. I'd like
I have the following code that downloads a video using AsyncTask. //DOWNLOAD VIDEOS private
I have a code that downloads videos from a URL. I am using AsyncTask.
I'm using using AsyncTask to download data over internet and I have a little
Have the following asynctask that i'm using to download some images. Works fine except

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.