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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:54:54+00:00 2026-06-08T02:54:54+00:00

Been searching for this issue for a while to no avail now: How to

  • 0

Been searching for this issue for a while to no avail now:

How to determine fragment is being restored from backstack?
I’m using the compatibility library and a ListFragment inside a FragmentActivity. When an item inside ListFragment is selected, a new Fragment is started to replace the ListFragment.

I noticed that when the FragmentActivity gets paused, the Fragment’s onSaveInstanceState is called. But when the Fragment is put into the back stack via FragmentTransaction, onSaveInstanceState doesn’t get called, then the lifecycle methods onCreateView and onActivityCreated gets called with null savedInstanceState Bundle.

I’m asking this because I want to load some data when the Fragment is created or restored, but not so when user comes back via. backstack.

I’ve looked at How to check if Fragment was restored from a backstack?
but want to add more details in hopes this would incite an answer.

Edit:
just noticed http://developer.android.com/reference/android/app/Fragment.html#onSaveInstanceState(android.os.Bundle)
says

Note however: this method may be called at any time before onDestroy(). There are many situations where a fragment may be mostly torn down (such as when placed on the back stack with no UI showing), but its state will not be saved until its owning activity actually needs to save its state.

So onSaveInstanceState is definitely out of the question…

  • 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-08T02:54:56+00:00Added an answer on June 8, 2026 at 2:54 am

    I think that most simple way is do this for example in onViewCreated() method:

    if (savedInstanceState == null && !mAlreadyLoaded) {
        mAlreadyLoaded = true;
    
        // Do this code only first time, not after rotation or reuse fragment from backstack
    }
    

    Because when android put fragment on backstack, it only destroy its view, but don’t kill instance itself, so mAlreadyLoaded will be still true when fragment will be restored from backstack.

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

Sidebar

Related Questions

I've been searching for a solution to this issue for a few days now.
I've been searching for a while for an explanation to this issue but getting
So I have been searching for a solution for this a while now, and
I've been struggling with this selection for a while now, I've been searching around
I've been searching for this for a while and keep coming up short. However
I'm really confused. I'm using Django 1.4 and I've been searching for this the
I've been searching on how to solve this issue but could not find any
I'm pretty much at my wits end with this issue. I've been searching for
I have been searching for a solution for this issue for multiple hours today
Okay, I've tried using Google-sensei and searching around on this website, and while I've

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.