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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:48:40+00:00 2026-06-04T00:48:40+00:00

In my application i am trying to open a dialog box when activity started

  • 0

In my application i am trying to open a dialog box when activity started and it has a positive button. on click on that button a new activity will open. Its working fine with following code. But when I long press menu button or search button dialog box get disappear. how can I make this dialog box remain constant even if i press menu or search button. thanks.

public class Sam3Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    TextView title = new TextView(this);
    title.setText("DM2");
    title.setBackgroundColor(Color.DKGRAY);
    title.setPadding(10, 10, 10, 10);
    title.setGravity(Gravity.CENTER);
    title.setTextColor(Color.WHITE);
    title.setTextSize(20);
    /* alert message */
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCustomTitle(title);

    builder.setMessage("dialog with message").setCancelable(false).setPositiveButton(
            "Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                    Log.d("choose","on dissmiss");
                startActivity(new Intent(getApplicationContext(),
                                                              StatisticDisplay.class));//second activity
                }
            });
    AlertDialog alert = builder.create();

    alert.show();
     }
}
  • 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-06-04T00:48:41+00:00Added an answer on June 4, 2026 at 12:48 am

    Take care of the Keys pressed by attaching an onKeyListener to the Dialog, in my example I’m just taking care of the search key, but you should get the point. In case you’ve never worked with listeners like this, returning true means the event should not propagate and is therefor taken care of preventing the system from catching the search key when pressed while showing the dialog.

    In any other case (the key not being the KEYCODE_SEARCH), it will just pass this listener as if it didn’t exist. 🙂

    ... 
    builder.setOnKeyListener(new OnKeyListener(){
                @Override
                public boolean onKey(DialogInterface dialog, 
                                     int keyCode,
                                     KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_SEARCH ) return true;
                    return false;
                }
            });
    ...
    

    Relevant documentation:

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

Sidebar

Related Questions

I'm trying to open a modal dialog as soon as a WPF application has
i am new to WPF, and i am trying to open a modal dialog
I'm trying to open default browser in Android from an application's dialog with a
I am trying to create a WPF application that will be a central point
I'm trying to install Laconica , an open-source Microblogging application on my Windows development
I just started with WPF and just now worked with open file dialog to
I'm trying to open a dialog window, but every time I try to open
I'm very new to jQuery and trying to run a pretty simple jQueryUI dialog
I'm trying to work through a problem I'm having with jQuery's dialog box in
My application is trying to open a text file, and is presented with a

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.