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

  • Home
  • SEARCH
  • 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 3352008
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:58:40+00:00 2026-05-18T01:58:40+00:00

Dear Android hackers, I am trying to do the following in my Android App:

  • 0

Dear Android hackers,
I am trying to do the following in my Android App: When the User clicks on a list item in a ListActivity, a ProgressDialog should show up, some preloading should happen and after it’s done, another Activity should be called using an intent.

I tried different approaches. What didn’t work at all was using an Async Task. Apparently I cannot show, dismiss or edit my ProgressDialog out of the Async Task, if that Class is not a Member of my original Activity.

I switched to a simple Thread then, this is how I’m trying to do it:

dialog = ProgressDialog.show(BookmarkActivity.this, "", "Loading...",true);
new Thread() {
    public void run() {
        // do something
        dialog.setMessage("Change Message...");
        // do more
        dialog.dismiss();
        // ...
        Intent intent = new Intent(BookmarkActivity.this, ThreadActivity.class);
        BookmarkActivity.this.startActivity(intent);
    }
}.start();

This works almost, but the changing of the dialog message does not. I’m getting errors saying something about “leaked windows”. (I can post the complete log if it is needed).

My questions:

  • How can I use an Async Task for this, where the Class has it’s own file?
  • How can I change the ProgressDialog out of my Thread or AsyncTask without causing an error for changing the UI in another thread?

Thanks in advance, Jan Oliver


Ok, with the help of Jason, I put together this Async Task. That works!

public class ThreadPreLoader extends AsyncTask<Object, String, Void> {

    private Activity mActivity;
    private ProgressDialog mDialog;

    public ThreadPreLoader(Activity activity) {
        mActivity = activity;
    }

    protected void onPreExecute() {
        mDialog = new ProgressDialog(mActivity);
        mDialog.setMessage("Loading...");
        mDialog.show();
    }

    protected Void doInBackground(Object... args) {
        publishProgress("Loading something else..");
        return null;
    }

    protected void onProgressUpdate(String... msg) {
        mDialog.setMessage(msg[0]);
    }

    protected void onPostExecute(Void result) {
        mDialog.dismiss();
    }
}

Thanks again, Jason.

  • 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-05-18T01:58:41+00:00Added an answer on May 18, 2026 at 1:58 am

    You should use an Async Task, Define a custom Async Task which receives the context (this) of the original activity.
    Then keep that context for later Dismissing the dialog.
    From your doInBackground() method you can call postProgress( int progress) which will cause onProgressUpdate() to be called in the async task , this method is on the UI thread so it will not cause cross thread errors.
    Once doInBackground() is complete the method onComplete() will also be called on the UI thread, this is where you can use your saved context and dissmiss the dialog (context.dissmissDialog()

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

Sidebar

Related Questions

Dear g++ hackers, I have the following question. When some data of an object
Dear Android hackers, I am attaching a gestureListener recognizing flings to a ListView. The
Dear Stacktoverflow, can you show me an example of how to use a QScrollBar?
Dear all, I have a question about Facebook Page: ( NOT user profile page,
Dear Folk's i'm using the following code in order to send the bytes of
dear all.can you tell me how to collecting this data in mysql: item colour
dear all, i'll take some data from the database. and join two tables.the code
dear all.I want to use only one textfield for different results. what should I
I am using floats for some Android Java game graphics, but the Math library
Dear Expert i have the following problem when i try to get the value

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.