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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:49:08+00:00 2026-06-01T22:49:08+00:00

I am working with a UI using tabs in the ActionBar. When switching between

  • 0

I am working with a UI using tabs in the ActionBar. When switching between tabs I am currently managing the Tab click events in my Activity and am calling attach and detach as needed using FragmentManager.

Each time a Fragment is attached I am going through the full lifecycle and creating a new view and loading all my data over again. I am using the given Bundle in onSaveInstanceState and onActivityCreated to update gui elements (mainly the scroll position of a list).

This is working OK, but has lots of overhead. In my case the list may have 300 or so records and there is a noticeable delay when switching between tabs.

In an effort to speed things up I am now saving the root view in onCreateView as a class variable. Then when onCreateView is called again as a result of the fragment being attached I test for a non null value for my root view and return it instead of re-inflating the view. This saved view still has the appropriate data set and I also bypass loading the data in this case. Of course I still need to fully rebuild the view and data if the Fragment is destroyed by OS while in the background.

My question is if this is a valid approach? I don’t see a downside to it unless there are memory issues to worry about.

  • 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-01T22:49:09+00:00Added an answer on June 1, 2026 at 10:49 pm

    It’s not the best approach, and here’s why:

    When you create the root view the first, all views are inflated using the Activity‘s context. If this Activity ever gets destroyed, and then you attempt to reattach the Fragment to a new instance of this Activity, you will have issues.

    Secondly, it’s a terrible use of memory to have a fully inflated root view sitting around when it’s not being used. Now, the records you mention are not stored in any View, but rather your list view has a reference to an adapter you created, which is keeping that adapter in memory along with your views. That is a lot of data to just have sitting around.

    Now to properly give you a recommendation, you ultimately have to draw a line between memory usage and performance, keeping in mind that if you plan to make this app public, there are a LOT of inferior hardware devices.

    One option is what you have already done, which is to make use of the savedInstanceState variable when being detached. You can try putting your 300 records in this Bundle and see how that performs. If the data is a class you have created, implement the Parcelable interface (see documentation to know how to properly implement this) and store it in the Bundle, and then retrieve it later and create a new adapter. I would highly advise against keeping references to Views between attachments.

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

Sidebar

Related Questions

For some reason, Vim keeps using soft-tabs (tabs as spaces) everytime I'm working on
So long story short, im working with some jquery tabs and im using this
I am using jQuery Tools Slideshow & Tabs for a project I am working
Is it possible to use tabs(indenting) in textarea using javascript. When tab button is
I am using jquery UI tabs and working pretty well and now I want
I am currently working on a project that is dealing with charts and tabs
I am currently working on a heavy web page. This page contains 5 tabs
I am using tabs, with Activity groups in each. I want to add an
I'm using a basic integration of jQuery Tools tabs function and it's working perfectly
I'm a tab person. Unless I'm working on a project that is already using

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.