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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:46:35+00:00 2026-06-06T18:46:35+00:00

I have a main menu activity with a bunch of buttons. One button starts

  • 0

I have a main menu activity with a bunch of buttons. One button starts a new activity that allows the user to fill out and submit a form. When the user submits the form, a third activity starts, basically just a screen with some content and a button to return to the main menu. However, when I create an intent and go to the main activity, setContentView() is not working and my button assignments cause a NullPointerException.

I know there is some way to go back in the stack, either via intent flags or calling finish(). I haven’t had success with intent flags such as Intent.FLAG_ACTIVITY_CLEAR_TOP. finish() will not work since I am two activities away, not one. What is the proper way of getting back to the main activity?

Thanks

  • 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-06T18:46:36+00:00Added an answer on June 6, 2026 at 6:46 pm

    There a bunch of ways you could do this. The easiest may be calling finish() on the second activity after it launches the intent, something like this:

    startActivity(activity3intent);
    finish();
    

    This will remove your second activity from the stack as the third one starts. Then, your MainMenu button can just call finish on the third activity, returning you to the first.

    If you’d prefer to do it with Intent Flags, try adding this to the Intent that calls Activity 1 from Activity 3:

    activity1intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    

    This will bring Activity 1 back into focus and clear anything that was above it on the Stack. The CLEAR_TOP flag handles getting rid of the rest of the stack, but IIRC, will not start a new instance of the Activity if it already exists on the stack. If you’d rather start a new instance of Activity 1, don’t use any flags, but call finish() after both activity 2 and 3 have sent their intents, so that they can’t be accessed through back navigation.

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

Sidebar

Related Questions

I have a log out button on my main menu and I want it
I have a main activity, that holds the main menu. This menu has an
I have an app that so far consists of two Activities: The Main Menu
I have an application that lives in the menubar, without a main menu or
I'm developing an app that starts with a main menu, and then continues through
I have this menu example But in this example new activity is not called,
In one Android activity I have added a context menu to an ImageView with
I have a main activity (main menu / home screen) Most of my game
I have two button's in the main menu. I invoking the camera when I
I have a menu and would like to open a new Activity when the

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.