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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:17:08+00:00 2026-05-14T23:17:08+00:00

In an Android application I run a task in a separate thread. While the

  • 0

In an Android application I run a task in a separate thread. While the thread is running it updates a progress bar in the main window to let the user know what’s going on. The problem is, that if a user starts the thread a second time the progress bar won’t be reset. It will just sit on 100% without doing anything.

The whole source is available on github. As an example take the BackupThread
and JsonBackup (the main class). Note that “RestoreThread” shows the same behaviour, but I assume that in both cases the problem is identical.

On to a quick walk through:

At around line 300 in JsonBackup.java, I open a new ProgressDialog. As it’s a new instance, I assume all is initialised properly. On my current working copy I have added a line setting the progress to “0”, but that didn’t change anything. In the same block, I create the backup thread and run it.

The next bit of code of interest is the moment when the thread communicates it’s progress back to the main application. This happens around line 185 of BackupThread.java.

The message is handled in line 80 of JsonBackup.java which will update the progress bar.

So far for the code walkthrough. One thing that struck me while writing this is line 87 of JsonBackup.java. I think it would be best if the thread sent a different message, explicitly stating that it’s done. But I assume this is not the real problem here. I say this because the progress dialog properly dismisses itself once it reaches 100%.

So, if this whole thing is run once, everything works as expected. Now assume, that the user leaves the application, but the OS decides to leave it loaded in memory. Later the user comes back and wants to create a new backup. Then the app won’t work as the progress hangs at 100%. If you kill the app, so it’s completely unloaded it will work again. So I assume that some object instance is still in memory and has an unclean state when re-run. But for the life of me, I cannot find what’s going on. As a tangent I might add: Apart from the Notepad tutorials, this is my first Android app, and bla di blah blah…

What am I missing here…?

  • 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-14T23:17:08+00:00Added an answer on May 14, 2026 at 11:17 pm

    The Dialog gets cached by Activity, that’s the expected behavior.
    Options are:

    1. override onPrepareDialog(..) to reset it’s state
    2. call removeDialog(..) before showing it again
    3. manage the dialog yourself, manually calling show(), dismiss()

    I usually go #1 for frequently used Dialogs and #3 for the rare ones.

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

Sidebar

Related Questions

I need to run a periodic task in an Android application. I currently use
How to run android application on netbeans 6.5? If i running the application means
i am develop an android application that let the user to insert some information
My android application has several warnings of the following form when I run it
I have developed the Hello World Android application using Eclipse. I can run the
I'm using the monkey tool to run a test of my Android application. For
When testing on real Android devices, I run my application from within Eclipse and
I recently uploaded my application to the android market however it's refusing to run
I am trying to run the Task-Android-sample given at Google Api Java Client I
I want to run this query in Android Application : SELECT field1 FROM table1

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.