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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:12:03+00:00 2026-06-09T01:12:03+00:00

I have two AsyncTask that are not working. There must be something in common

  • 0

I have two AsyncTask that are not working. There must be something in common with both I am doing wrong.

My first activity takes a long time to load so I wish to have a progressDialog/Bar but it fails. I access a AsyncTask in my onCreate with

new HeavyWorker(this).execute();


public class HeavyWorker extends AsyncTask < String , Context , Void > {

    private ProgressDialog      progressDialog ;
    private Context             targetCtx ;

    public HeavyWorker ( Context context ) {
        this.targetCtx = context ;
   //     this.needToShow = true;
        progressDialog = new ProgressDialog ( targetCtx ) ;
        progressDialog.setCancelable ( false ) ;
        progressDialog.setMessage ( "Retrieving data..." ) ;
        progressDialog.setTitle ( "Please wait" ) ;
        progressDialog.setIndeterminate ( true ) ;
    }

    @ Override
    protected void onPreExecute ( ) {
        progressDialog.show ( ) ;
    }

    @ Override
    protected Void doInBackground ( String ... params ) {
      // Do Your WORK here

These lines below work fine when in the normal
“public void onCreate(Bundle savedInstanceState)” area

        Ls = new LoadSettings(CreateAppointment.this);
        gs = new GlobalSubs();

        TimeZoneList();

This line dynamically fills a Spinner box and stops it from working, so I commented it out.

    //      createTimezone();
        ZoneList(Ls.getCountryZone());

This line also fills a spinnerbox dynamicly so I commented it out

    //  createZone();
        InitialiseUI();
        CreateFileName();

       return null ;
    }

This area is never reached?

    @ Override
    protected void onPostExecute ( Void result ) {
        if(progressDialog != null && progressDialog.isShowing()){
            progressDialog.dismiss ( ) ;
        }
    }
}

My second page fails with the same style of problem.
I’ve also tried in a settings page with slightly different code.
Fixed now with:

//
private class MyClass extends AsyncTask<Void, Void, Void>{

ProgressDialog mProgressDialog;

public MyClass(){

mProgressDialog = new ProgressDialog(Preferences.this);
mProgressDialog.setMessage ("Please Wait While Saving");
mProgressDialog.setTitle("Saving");

//

@Override
 protected void onPreExecute() {
    super.onPreExecute();
    mProgressDialog.show(Preferences.this, "Saving", "Please Wait a Sec");
 }

@Override
protected Void doInBackground(Void... params)
    {
        saveSettings();
        return null;
    }

@Override
 protected void onPostExecute(Void unused) {

The only way it works is when I comment out the line and change to a different activity

//   mProgressDialog.dismiss();
        Toast.makeText(Preferences.this, "Your Settings Where Saved.", Toast.LENGTH_SHORT).show();
     gotoMainPage();
 }

}

    private void gotoMainPage(){
        Intent a = new Intent(this, Main_entry.class);
        finish();
        startActivity(a);
    }
  • 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-09T01:12:05+00:00Added an answer on June 9, 2026 at 1:12 am

    You are not supposed to be doing anything to the UI in the background. doInBackground() runs on a background thread. If you need to update the UI during the background process, you use publishProgress() (and onProgressUpdate()) for that.

    It looks to me like you’re still trying to perform UI operations here:

        //  createZone();
        InitialiseUI();
        CreateFileName();
    

    I don’t know what InitialiseUI() does, but it sounds UI-ish. If you need UI setup, do that in preExecute(), which is called on the UI thread.

    Can you just set a breakpoint in your doInBackground() method, see how far it’s getting, and let us know? That would help.

    On your second example, you say it’s failing in onPostExecute() here:

    mProgressDialog.dismiss();
    

    There’s really only one way for that to fail. If mProgressDialog is null. Can you check the constructor of this class, and make sure you remembered to instantiate it?

    P.S. You have the second generic parameter as Context in your first AsyncTask subclass. But, you don’t seem to use it. Normally, that would be the type of the data that doInBackground() passes to onProgressUpdate() via publishProgress().

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

Sidebar

Related Questions

I have two activities; Home is my first activity and Settings is my second
Let say that I have two Activity to develop in Android. Upon the end
I have two total different implementations of AsyncTask , lets say AT1 and AT2
I have two update panels on a page. And I want to update both
I have two tables, lets say table1 and table2 with common columns, id and
I have three simultaneous instances of an AsyncTask for download three files. When two
I have two functions that access the internet on the APP start. I've tried
In my application I have two threads (I'm using AsyncTask class). in doInBackground() method
I have two AsyncTasks that I am using, one is called up after a
In my app I have a background task (using AsyncTask) that downloads stuff from

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.