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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:11:21+00:00 2026-06-18T00:11:21+00:00

I have a header bar (kinda like menu) and 4 fragments (MAIN, A, B,

  • 0

I have a header bar (kinda like menu) and 4 fragments (MAIN, A, B, C) from which the MAIN should be ‘main/root’ fragment for backstack.

Problem i have is when user via menu goes for example MAIN > A > B > C.
If i simply use backstack it will go in reverse order which i don’t want.
I need back button to go back to MAIN no matter how user navigated to one of those 3.

enter image description here

My current code (which is wrong, it quits app when not in MAIN and current fragment is switched from other non-MAIN fragment) looks like this:

private void SwitchFragment(Fragment pFragment)
{
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.main_fl_fragmentcontainer, pFragment);
    if (_CurrentFragment == _Frag_Main)
        ft.addToBackStack(null);
    ft.commit();

    _CurrentFragment = pFragment;
}
  • 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-18T00:11:22+00:00Added an answer on June 18, 2026 at 12:11 am

    Your stack must contains 2 fragments at maximum

    Main is visible
    Main is onBackstack / AorBorC is visible.
    User click on back ==> Main is visible.
    User click on back ==> application end

    I suppose A / B / C are displayed in the same view so in this case,

    When user click on your Menu, you have to check if A/ B / C is currently displayed and replace it by the one selected by the user.

    private void displayFragment(Fragment pFragment) {
        Fragment fr = getSupportFragmentManager()
                .findFragmentById(R.id.main_fl_fragmentcontainer);        
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.main_fl_fragmentcontainer, pFragment);
        if (_CurrentFragment == _Frag_Main) {
            ft.addToBackStack(null);
        }
        ft.commit();    
        _CurrentFragment = pFragment;
    }
    

    can override OnBackPressed method of your activity.

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

Sidebar

Related Questions

I Have site change.is, where right side menu & search bar in header is
I have two divs: -A header bar, which is fixed while scrolling, and stuck
In my app I have a header bar which consists of a single textview
I have a header and menu bar that I have fixed to stay at
I currently have a login popup in my header bar which is on every
I have a Header/navigation bar on a site, it has a logo, navigation menu,
I have a page design I'm trying to implement with a header (menu bar)
I have a file like HEADER foo bar garbage SUBHEADER foo foo bar other
What i want to do is as follows: I have a header bar at
Imagine I have a navigation bar in my page header, with a number of

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.