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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:48:56+00:00 2026-06-13T12:48:56+00:00

The phone back button has me baffled. This question has been asked many times,

  • 0

The phone back button has me baffled. This question has been asked many times, but i have NOT got the solution. So asking again as per my requirement.

I have a home screen activity
It calls 3 activities – which in turn calls 2 activity each.

Assume i navigate this way

Home > Act1 > SubAct1a > SubAct1b > Home (through a Home button) > Act2 > Home > Act3

Now in Act3, when i press the phone BACK button, i get to Home. My REQUIREMENT at this point is when i press the BACK button again , it should EXIT the app. But what happens it it goes like this

Act2 > Home > SubAct1b > SubAct1a > Act1 > Home > EXIT

So the user is pressing BACK MULTIPLE times before he quits the app.

Pressing the HOME key is an option, but i want the BACK to work correctly as well.

I have this piece of code in the HOME activity – but it does not work at all

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

    return super.onKeyDown(keyCode, event);
}

It just returns to the previous activity it was at.

  • 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-13T12:48:57+00:00Added an answer on June 13, 2026 at 12:48 pm

    You should return true, to tell the system that you already handled this situation,

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

    When you start your home activity, try setting the clear top flag…

    Intent intent = new Intent(this, HomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just asked a question about this but I want to go at it
Has anyone encountered this problem with Windows Phone 7.1? I have a simple page
This is specifically a Caliburn.Micro question I think, as it has to do with
I have been building a launcher app with many activities. I want the home
I have a question about the expected behavior of Window Phone 7.5 emulator. If
When the BACK button is pressed on the phone, I want to prevent a
I'm new to development on Windows Phone 7 and Silverlight but I do have
How do I get the back button from Windows phone to work with PhoneGap
Possible Duplicate: Windows Phone 7 Search Button I think that all Windows Phone mobiles
I have a phone caller id device. I want to record calling numbers to

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.