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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:27:11+00:00 2026-05-23T03:27:11+00:00

I have tried a lot of ways to trigger the backPressed () event when

  • 0

I have tried a lot of ways to trigger the backPressed() event when the progressDialog is displayed. But none works. If I provide progDialog.setcancelable(true); I am able to dismiss the progressDialog but still the onBackPressed() doesn’t get triggered.

  • 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-23T03:27:12+00:00Added an answer on May 23, 2026 at 3:27 am

    When ProgressDialog is active if yiou press back key to perform yopur own operations you have to set setOnCancelListener to the progressdialog.
    write your logic inside onCancel() method example the whole logic that you have written in onBackPressed() event those things you have to write here.

    Sample code

    import android.app.Activity;
    
    import android.app.ProgressDialog;
    import android.content.DialogInterface;
    import android.content.DialogInterface.OnCancelListener;
    
    import android.os.Bundle;
    
    import android.view.KeyEvent;
    import android.view.View;
    
    import android.view.View.OnClickListener;
    
    import android.widget.Button;
    
    public class CancelProgressDialog extends Activity {
    
        ProgressDialog myProgressDialog = null;
    
        @Override
        public void onCreate(Bundle icicle) {
    
            super.onCreate(icicle);
    
            /* Create a very simple button */
    
            Button b = new Button(this);
    
            this.setContentView(b);
    
            b.setText("Show ProgressBar...");
    
            b.setOnClickListener(myProgressBarShower);
    
        }
    
    
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            System.out.println("...any key is pressed....");
            if (keyCode == KeyEvent.KEYCODE_BACK)
            {
                System.out.println("...BackButton is pressed...");
                if( (myProgressDialog!= null) && myProgressDialog.isShowing()){
                    myProgressDialog.dismiss();
                }
            }
            return super.onKeyDown(keyCode, event);
        }
    
        /** OnClickListener that fakes some work to be done. */
    
        OnClickListener myProgressBarShower = new OnClickListener() {
    
            // @Override
    
            public void onClick(View arg0) {
    
                // Display an indeterminate Progress-Dialog
    
                myProgressDialog = ProgressDialog.show(CancelProgressDialog.this,
    
                "Please wait...", "Doing Extreme Calculations...", true);
                myProgressDialog.setOnCancelListener(new OnCancelListener() {
    
                    public void onCancel(DialogInterface arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("...cancel button is pressed");
    //                  perform your task here
                    }
                });
                myProgressDialog.setCancelable(true);
    
    
    
            }
    
    
    
        };
    
    }
    

    Thanks
    Deepak

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

Sidebar

Related Questions

I have tried this a few different ways but none of them seem to
I have tried a lot of solutions but it did not work for me
I have tried a lot but not been able to understand the steps involved
I have searched a lot and tried much but I can not find the
I have tried searching over the internet about this problem but not able to
I have tried many permutations but they all don't seems to work well. Am
I have asp.net website name http://www.go4sharepoint.com I have tried almost all ways to improve
I've seen this question asked a lot of times but no ways to do
I have recently tried sharpening my rails skills with this tool: http://github.com/edgecase/ruby_koans but I
I'm trying to parse JSON into NSDictionary. I have tried a lot of different

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.