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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:01:49+00:00 2026-06-05T19:01:49+00:00

Guys I have an activity which has a home button, when the button is

  • 0

Guys I have an activity which has a home button, when the button is pressed,an alert dialog should appear with the message “Exit without Saving ?”
and the following options(buttons) should be available to the user:

1-> Yes

2->No

3->Save and Exit

But the problem is when the home button is pressed NO alert dialog is being displayed.

I tried the following code:

// this is when the button is pressed

public void onClick(View v) {
    // TODO Auto-generated method stub
switch (v.getId()) {

case R.id.backHome:
        final AlertDialog alertDialog = new AlertDialog.Builder(
                DataView.this).create();
        // alertDialog.setTitle("Exit Without Save ?");
        alertDialog.setMessage("Exit Without Saving");
        alertDialog.setButton("Yes", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                Intent i = new Intent(DataView.this, DiaryActivity.class);
                startActivity(i);
                finish();

            }
        });

        alertDialog.setButton2("No", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                alertDialog.dismiss();

            }
        });
        alertDialog.setButton3("Save and Exit",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        rowIdreceived = getdata.getLong("row_id");
                        String title_updated = topicDisplay.getText()
                                .toString() + " ";
                        String story_updated = StoryField.getText()
                                .toString();
                        DataHolder entry = new DataHolder(DataView.this);

                        try {
                            entry.open();
                        } catch (SQLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        entry.updateEntry(rowIdreceived, title_updated,
                                story_updated);

                        entry.close();
                        Intent i = new Intent(DataView.this,
                                DiaryActivity.class);
                        startActivity(i);
                        finish();

                    }
                });


        break;

The DiaryActivity is the main class.

DataView is the current activity.

The Yes button simply exits out of the current activity and goes back the main activity that is the DiaryActivity.

The No button “dismisses” the alert dialog and the user can then save his work and exit later.

The save and exit button save the work into the database and then exits out of the current activity to the main activity.

  • 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-05T19:01:51+00:00Added an answer on June 5, 2026 at 7:01 pm

    theck out this. call alertDialog.show(); to show alertdialog

    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Reset...");
    alertDialog.setMessage("Are you sure?");
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int which) {
          // here you can add functions
       }
    });
    alertDialog.setIcon(R.drawable.icon);
    alertDialog.show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi guys i have a model livestream which has two columns in the database,
I have a application developed in ActionScript 2 which has dragging/dropping activity. which works
guys i have arrays in which i have to match this kind of text
i have Target.java(it is the main activity) and Layout.java. When user clicks a button
Guys sorry if sounds a little bit naive... In an activity I have one
I am writing an Android app in which I have a Map activity where
hey there guys and girls i have this code that should download a json
I have an app, that has an Activity that uses a ScrollView . I
do you guys have any idea how to edit the the labels in the
Thus far you guys have been wildly helpful with me getting this little ditty

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.