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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:55:05+00:00 2026-05-23T03:55:05+00:00

I’ve created a simple TabActivity which builds tabs at runtime reading some JSON data.

  • 0

I’ve created a simple TabActivity which builds tabs at runtime reading some JSON data. At the moment I’m initializing an empty ListActivity with dummy random items for each tab just to see that changing from tab to tab works and the content doesn’t disappear. The actual content for the tabs is stored in a singleton class, so when the tab activities get re-created due to a screen orientation change, they just pull the correct dummy items from the respective list according to an identifier contained in the intent’s extras bundle.

Everything works fine. I’ve put a log on the list activity onCreate method to watch the activities get recreated on screen rotation, and they do. However, there is something strange in that the activity for the first tab is always recreated, even if it is not visible. When I switch to the third or fourth tab and rotate the device, the previous tabs get killed and don’t get recreated again, except the first tab. The first tab is always there. Why? I would understand a bug in the code, but the tab activity is copied from a tutorial and the list activity is the same for all tabs. Here are some logs I get:

List created with 1
onConfigurationChanged
List created with 1
List created with 2
List created with 4
List created with 5
List created with 6
onConfigurationChanged
List created with 1
List created with 6
onConfigurationChanged
List created with 1
List created with 6
onConfigurationChanged
List created with 1
onConfigurationChanged
List created with 1
List created with 2
onConfigurationChanged
List created with 1
List created with 2
onConfigurationChanged
List created with 1
List created with 2
List created with 4
onConfigurationChanged
List created with 1
List created with 4
onConfigurationChanged
List created with 1
List created with 4
List created with 5
onConfigurationChanged
List created with 1
List created with 5
onConfigurationChanged
List created with 1
List created with 5

As you can see from the logs, each list activity logs the identifier put in the extras bundle, and does pretty much nothing else. So the application starts and the first tab gets created, then I rotate and switch to the other tabs. Their onCreate method is called. And then the log shows how I’m switching tabs and rotating. Different activities get recreated depending on which tab is visible, but the first one is always there!

Why is the first tab always being recreated? Is this special behavior needed for some reason? I’m seeing this on an HTC Legend API level 7.

UPDATE: I’ve put some more logs in the TabActivity’s loop creating the individual tabs, and it looks like when the first tab is added its activity is always created. Is there any way to avoid this? Maybe create dummy empty tabs and later populate them with the real activities? Some more logs:

onConfigurationChanged
Tab: Saving tab index 3
...
Tab: Adding tab 1
List created with 1
Tab: Adding tab 2
Tab: Adding tab 3
Tab: Adding tab 4
Tab: Adding tab 5
Tab: Setting tab to index 3
List created with 5
  • 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-05-23T03:55:06+00:00Added an answer on May 23, 2026 at 3:55 am

    After putting some more logs in the activity’s lifecycle methods, I found out that the onCreate() and onStart() methods are always created for the first tab, but the onResume() method is only called for the visible tab. So I will put my lazy initialisation code on the onResume() method to avoid the first activity bog down the application.

    Possibly the TabActivity works internally in a similar way to a http://developer.android.com/reference/android/widget/ViewFlipper.html and that’s why the first tab activity is always created despite not being visible.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have a text area in my form which accepts all possible characters from

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.