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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:41:09+00:00 2026-06-12T22:41:09+00:00

I created a dialog activity using the following snippet. I’m using a translucent theme

  • 0

I created a dialog activity using the following snippet. I’m using a translucent theme for this activity.So it looks neat.

public class DialogActivity extends Activity {
AlertDialog alertDialog;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Title");
    alertDialog.setMessage("Body");
    alertDialog.setIcon(R.drawable.ic_launcher);
    aleratDialog.setButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            DialogActivity.this.finish();
        }
    });

    alertDialog.show();
}

@Override
protected void onPause() {
    if(alertDialog!=null) {alertDialog.dismiss();}
    super.onPause();

}

@Override
protected void onStop() {
    if(alertDialog!=null) {alertDialog.dismiss();}
    super.onStop();

}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        finish();
    }
    return super.onKeyDown(keyCode, event);
}


}

I am having trouble when the user clicks on the Back button. The activity still stays on foreground when the user does that. I tried overriding the onKeyDown method to call finish() when the user tries to go back but this didn’t help.

Note: The onBackPressed or onKeyDown methods are not invoked when I press back for the first time.(The ActionBar stays) I have to press it a second time to get there and then the activity actually disappears

I think this has got something to do with my Manifest entry

<activity
        android:name=".DialogActivity"
        android:launchMode="singleInstance"
        android:noHistory="true"
        android:label="@string/app_name"
        android:configChanges="orientation"
        android:theme="@android:style/Theme.Holo.Dialog" />
  • 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-12T22:41:10+00:00Added an answer on June 12, 2026 at 10:41 pm

    What you are doing is create a dialog (the DialogActivity), and from it open another dialog with the alert builder. So you get 2 dialogs, and clicking back removes the alert dialog, but not the DialogActivity.
    Why do you need the DialogActivity? Why not open the alert from the calling activity ?

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

Sidebar

Related Questions

I am using this simple code public class Main extends Activity { private ProgressDialog
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',
I'm using DOJO v1.7.2. I've created Datagrid in Dialog widget declaratively. I've included needed
i m using the following code to finish an activity but i want to
I have created an AlertDialog using AlertDialog.Builder, but the Dialog border takes up too
I'm opening an alert dialog from an activity using the 'onCreateDialog' method: protected Dialog
I created a custom dialog and I'd like to start a new activity when
I am using a Progress Dialog to show the progress of the activity.It starts
I see many developers choosing to theme their activity as a dialog instead of
Is there other way to create an Activity inside an Activity without using Dialog

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.