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

  • Home
  • SEARCH
  • 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 7822609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:58:04+00:00 2026-06-02T07:58:04+00:00

Please have a look at the graph: https://i.stack.imgur.com/G2lfN.png I have some trouble with the

  • 0

Please have a look at the graph: https://i.stack.imgur.com/G2lfN.png

I have some trouble with the architecture of my app. I have a few Activity/states that if you reach them you are not allowed to go back. These are K, A and X, so when you reach them and press back button you will close my app.

It is very easy with START Activity. As soon as I do some work to decide if I go to K or A, I just run START.finish() and that is what I want (being in K or A Activity and pressing back button closes app as START Activity no longer exist).

The problem starts with X state. The application is like you need to fullfill 3 steps so you go through:

[START]->[A<->B<->C]->[X]

The requirements are while pressing back button:

on A: closes app

on B: show A

on C: show B

If you then finally finish some kind of wizard (A->B->C) you reach X where if you only press back button you closes app.

QUESTION: How should I finish() A, B, C to prevent back button from X? I have no reference to use.

  • 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-02T07:58:07+00:00Added an answer on June 2, 2026 at 7:58 am

    One way to achieve this, is in activity X, make pressing the back button fire of a custom event.

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

    You’ll notice the above method has the line Globals.finished = true; This refers to a class called Global with a static (static can be called on a class without having to instantiate an object) boolean variable called finished that is initially set to false as follows. In my own apps I often use a Globals class for sharing things common to the whole app. You can also used the shared preferences to do somthing similar.

    public class Globals
    {
      public static finished = false;
    }
    

    Then in the onResume (or possibly onStart) lifecycle method of all activities you can put the following

    if (Globals.finished == true)
        finish();
    

    This will cause, all the activities to immediately close, but only once the finish variable in the Globals is true. I’ve done this before and it works quite well and will ensure the activities call their life cycle methods on closing.

    Even simpler than this, you could avoid the use of the back button event handler, by setting the Globals.finished = true, in the onClose method of ActivityX.

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

Sidebar

Related Questions

Please have a look on this application http://itunes.apple.com/app/yowza-mobile-coupons/id312021877?mt=8 I just want to add custom
Would you please have a look at Tipulator app: http://www.sophiestication.com/tipulator/ I'm interested in the
Please have a look at this validation array in my cakephp app for model
Please have a look: http://bestdesign.com.pl/klienci/tasta/strona/ Under the slides there are 4 divs with hover's
Please have a look at the following code: <HTML> <HEAD> <script src=//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js type=text/javascript></script> <SCRIPT
Please have a look at beta.gulfdine.com. You will see a Sign in link. Clicking
Please have a look at this screenshot alt text http://www.maclife.com/files/u18/Yep3-big.jpg I think these are
Please have a look at this image Grid Showing Pending Work http://softwaregenius.net/myimages/grid.png The image
Please have a look: So basically I have a tree like architecture which is
Please have a look at this form that I am trying to design with

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.