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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:37:41+00:00 2026-05-27T23:37:41+00:00

In my main activity, i call a dialog which is cancelable. I show this

  • 0

In my main activity, i call a dialog which is cancelable. I show this dialog when user lunches the app while he is not connected to Internet. therefore, I show this dialog to ask him connect to Internet.

This dialog doesn’t have button and I want to close application when user clicks back button. In onKeyDown() method, I’m closing the application (this.finish();) but the problem is when dialog is displaying on screen when user clicks back button, this dialog disappear and my main activity is show.

It seems onKeyDown() just work in main activity not for dialog. How to close my app when dialog is display and user clicks back button?

Thanks

=====>
Update

This is the code of my custom dialog:

private void initWarningDialog(){
        dialogWarning = new Dialog(DRMActivity.this, R.style.customDialogStyle);
        dialogWarning.setTitle("Warning!");
        dialogWarning.setContentView(R.layout.dialogwarning);
        dialogWarning.setCancelable(true);
    }
  • 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-27T23:37:42+00:00Added an answer on May 27, 2026 at 11:37 pm

    Only call finish() method:

    dialog.setPositiveButton("Ok",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Finish activity
                finish();
            }
        });
    

    Update:

    As you are having custom dialog, i would suggest you to set OnCancelListner, something like:

    dialogWarning.setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    // TODO Auto-generated method stub                  
    
                    finish();
                }
     });
    

    Update-2:

    It is really annoying because how user can come to know if he press the back key then actual activity will close. Instead you should provide atleast “ok” button to let user click.

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

Sidebar

Related Questions

I have main activity which call other object, for example GPS class. This GPS
I have a widget that supposed to call an Activity of the main app
I have a Activity called main. If I call Toast.makeText(this, Hello World from main,
I am launching activities from the main activity in my app using the call
I have a main Activity and a Dialog through which I would like to
I have the first activity that call a dialog from second activity with this
I have a main activity, then i call a new activity intent from this.
i have main activity in which i have Four menus. and i have one
The first activity in my app is a splash screen with a Progress Dialog
My MAIN activity is spawning a child activity that contains a ListView . While

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.