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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:53:21+00:00 2026-06-15T14:53:21+00:00

In a Fragment i have this: onPause(){ super.onPause(); if(flag){ getActivity.finish(); }else{ } } onResume(){

  • 0

In a Fragment i have this:

onPause(){

super.onPause();
if(flag){
getActivity.finish();
}else{
}
}

onResume(){

flag = true;
super.onResume();
}

and there is a Button, on click i set this flag to false:

Button.onClick{
flag = false;
}

The idea is:

when the button is clicked don’t finish this Activity. But when device BackButton is pressed finish().

But this logic isn’t working. The reason is, when i press BackButton of the device, onPause is not being called.

This is the 4th Fragment in the Activty. So when i press BackButton i can see the 3rd Fragment. Which i don’t want to.

I am using this on a API 10 device, But my application uses support library v4.

Thank You.

  • 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-15T14:53:22+00:00Added an answer on June 15, 2026 at 2:53 pm

    If you want to close the activity on the back press, then Override the onBackPressed inside the activity as following:

    public void onBackPressed() {
       Fragment fragment = getSupportFragmentManager().findFragmentByTag("yourfragment");
       if (fragment instanceOf YourFragmet) {
              finish();
              return;
       }
       super.onBackPressed();
    }
    

    If you want to close the activity on the button click, then you can call

    Button.onClick{
      getActivity().onBackPressed();
    }
    

    OR

    Button.onClick{
      getActivity().finish();
    }
    

    If When you are transitioning between Fragments, you call addToBackStack() as part of your FragmentTransaction, then the back button will take you to the fragment on the top of the back stack

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

Sidebar

Related Questions

I have fragment that on a component click pop-ups DialogFragment. This dialog fragment holds
I have this application where I implement the ActionBar Fragment interface. Underlying the interface,
Say I have this HTML fragment <td width=25% style=text-align:right; > <span style=font-family: Arial; font-size:
I have a Fragment with ImageView . How I can show this Fragment on
Using this sample : I have make my own Fragment that holds tabhost and
I have an xml layout for a Fragment (android.support.v4.app.Fragment). When this Fragment is added
I have this code fragment: public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
I have this code fragment int i = 5; int k = 7; int
So, I have this code fragment: int * iPtr ; int * jPtr ;
I have this fragment of code: SmsDataClassesDataContext dc = new SmsDataClassesDataContext(); // Get 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.