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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:49:45+00:00 2026-05-20T10:49:45+00:00

In android I have an TabActivity (A) in which I create a single tab

  • 0

In android I have an TabActivity (A) in which I create a single tab called loading with the Activity B.

From Activity B I modify the TabWidget from TabActivity A to add some more tabs via a static reference to the TabHost in TabActivity A.

After I start a new activity C and then press BACK the TabWidget has only one single tab called Loading.

I’ve tried in the onResume method of Activity B to recreate the tabs but it doesn’t work anymore.

Does anyone know why does it do this and how can I fix it?

  • 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-20T10:49:46+00:00Added an answer on May 20, 2026 at 10:49 am

    Relying on static variables pointing to UI components (like a TabHost) can lead to produce memory leaks. Don’t do it. Instead register a BroadcastReceiver in the TabActivity to add new tabs. That way, instead of modifying a static variable, you send a broadcast (Context#sendBroadcast(Intent)) to tell the tab activity that you want a new tab.

    Also, make sure you save the state of the TabActivity, so that you can restore it if the Android OS destroys your activity for some reason. I recommend using the onRetainNonConfigurationInstance… something like this:

    private State mState;
    public void onCreate(Bundle b){
        // somewhere in onCreate
        mState = (State) getLastNonConfigurationInstance();
        if( mState == null ){
            mState = new State();
        } else {
            for(TabSpec tab : mState.tabs){
                //add them to the tab host
            }
        }
    }
    @Override
    public Object onRetainNonConfigurationInstance() {
        return mState;
    }
    
    private static class State{
        List<TabSpec> tabs;
        // more stuff that you want to save
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android application which has four tabs (I use a main TabActivity
Having some trouble passing values from one class to another. I basically have a
My Android app, which uses a TabActivity to display its contents, has 4 tabs
I have a TabActivity with a single ListView inside TabHost's FrameLayout. This ListView is
I have a basic TabActivity. On android 2.1 (and possibly older versions), it looks
I have an android app that extends a MapActivity, so I can't extend TabActivity.
I implement a TabActivity exactly like this - http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/ Now the problem is, I
So I've just got myself an Android device and wanted to have a go
I have an application about debts to user and user's debts. Main activity is
So, I'm both new to Java and to creating android apps, but not new

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.