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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:51:31+00:00 2026-05-25T15:51:31+00:00

Actually i have a problen while using progress dialog.The problem is not with the

  • 0

Actually i have a problen while using progress dialog.The problem is not with the progress dialog.What i find difficult is.

I call a function onPause() of an activty say

public void onPause()
{
   super.onPause();
   setData();
}

Now onBackpressed() method i display an progressdialog, and the code i have use is

public void onBackPressed() 
{           
    final ProgressDialog progressDialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);
    Thread reminderThread = new Thread() 
    {
        public void run()
        {
            try
            {
                Thread.sleep(3 * 1000);
                ReminderForm.this.finish();
                progressDialog.dismiss();                           
            } 
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    };reminderThread.start();
 }

Now my problem is that when i enter Data and call setData() on the onPause() method it takes times to exit from at that activity.So during that time i display the progress bar when the user click back button.so these work fine but when the user enter no data then i want the progress bar to show but with less time as shown when the user enter data and call the setData() method of onPause() method.But in my case whether the user enter data or not the progressBar will take 3 sec.So is there any way where i can get the time of first thread and put that time in my second thread.

  • 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-25T15:51:32+00:00Added an answer on May 25, 2026 at 3:51 pm

    Handler.postDelayed method would be your friend in this case. Instead of spawning a new thread and executing code to perform a delay, Handler.postDelayed will allow you to set the amount of time to wait and pass in a Runnable to be executed on the UI thread.

    http://developer.android.com/reference/android/os/Handler.html#postDelayed%28java.lang.Runnable,%20long%29

    EDIT

    Actually, I take that back. After re-reading, it seems what you want to do is save state when the user presses the back button, show a dialog during this time, and then dismiss the dialog and finish the activity when done. This is what you need:

    @Override
    public void onBackPressed() {
        new SaveStateTask().execute();
    }
    
    protected void saveMyActivityState() {
        // Do your stuff for however long it takes...
        // This is executing on a background thread...
    }
    
    class SaveStateTask extends AsyncTask<Void, Void, Void>
    {
        ProgressDialog progressDialog;
    
        @Override
        protected void onPreExecute() {
            progressDialog = ProgressDialog.show(NameOfYourActivity.this, "", "Loading. Please wait...", true);
        }
    
        @Override
        protected void onPostExecute(Void result) {
            progressDialog.dismiss();
            NameOfYourActivity.this.finish();
        }
    
        @Override
        protected Void doInBackground(Void... arg0) {
    
            saveMyActivityState();
    
            return null;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a school problem but I do not understand what it actually asks.
I have a problem: i need to find an average of the list using
I actually have two questions regarding the same problem but I think it is
I have a problem. Actually in our application, earlier the customer was allowed to
I actually have an answer to my question but it is not parallelized so
I have heard that it's best not to actually have any html in your
I have a problem while dealing with a data set which the value range
I have a problem that whenever I'm inserting data using coredata, everything's going fine.
Hi friends hope all r doing well. I have a problem while reading xml
Actually I'm working on very simple FTP server. Now I have problem with sending

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.