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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:53:53+00:00 2026-05-20T09:53:53+00:00

I want to be able to control which activities the user can press the

  • 0

I want to be able to control which activities the user can press the back button into, depending on where the user is currently. For example, I have Activities A, B, C, and D.

The user navigates (through buttons I provide) from Activity A, to B, to C, and finally, to D. If the user presses back any time before D, I want the normal back operation (if they press back on Activity C, they will be presented with B).

However, if they make it all the way to D, I want to finish activities B and C. Now, when the user clicks back, I want them to be presented with A.

  • 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-05-20T09:53:53+00:00Added an answer on May 20, 2026 at 9:53 am

    This can be done easily by intercepting the Back button keypress event and providing your own handling code.

    So in your Activity D, you will have the following code:

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
    
            // finish activties, change parents, whatever
    
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    

    EDIT (due to misuderstanding):

    You can pass the references to the Context of your previous activities in a Bundle as an extra inside the Intent you use to start your new Activities. I believe that Context is Parcelable, so you should be good. BTW, you need the Context of those Activities so that you can do something like ActivityOneCOntext.finish ();.

    [[EDITED, NOT WORKING]]

    However, you should be careful with these references, as each alive reference to an Activity’s Context prevents the garbage collector from releasing the resources allocated for that Activity. If your Activity finishes and you still keep a reference somewhere in another Activity, you will have a (sort of a) memory leak.

    EDIT2:

    Obviously the code above was not working.

    You can use this method to get a reference to the current Activity’s parent’s Context:

    Context parentContext = (Context) this.getParent ();
    

    So, needles to say, you can have a grand-parent’s context like this:

    Context gParentContext = (Context) ((this.getParent ()).getParent ());
    

    You can see the reference hare.

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

Sidebar

Related Questions

I have an ascx control which contains dropdownboxes I want to be able to
I've written a web user control which I want to be able to drop
I have a user control which contains a number of child controls. I want
I have a Tab Control with multiple Tab Pages. I want to be able
I have a custom control which contains a panel, of which I want to
I have a simple user control which wraps some logic around an AutoCompleteBox. This
I have multiple superposed controls which can handle a mouse click under certain conditions.
Using jQuery I want to be able to click an element which will also
I want to have generalised email templates. Currently I have multiple email templates with
If all tables I want to delete from have the column gamer_id can i

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.