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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:56:48+00:00 2026-06-10T22:56:48+00:00

I have a problem with onConfigurationChanged and TabHost. Because my Activity restart on rotation,

  • 0

I have a problem with onConfigurationChanged and TabHost.
Because my Activity restart on rotation, I found this very helpful post:
Activity restart on rotation Android

I sort gui elements out to the function InitialGui()

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    InitialGui();
}

Override onConfigurationChanged and call InitialGui()

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.main);
    InitialGui();
}

Inside AndroidManifest

    <activity
        android:label="@string/app_name"
        android:name=".MyAndroidAppActivity"
        android:theme="@android:style/Theme.NoTitleBar"
        android:configChanges="keyboardHidden|orientation"
        >

For simplicity I create a new project based on
http://www.mkyong.com/android/android-tablayout-example/
with only mentioned changes.
This is btw the InitialGui function

public void InitialGui()
{
    TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
    tabHost.setup();

    // Android tab
    Intent intentAndroid = new Intent().setClass(this, AndroidActivity.class);
    TabSpec tabSpecAndroid = tabHost
      .newTabSpec("Android")
      .setIndicator("Android")
      .setContent(intentAndroid);

    // Apple tab
    Intent intentApple = new Intent().setClass(this, AppleActivity.class);
    TabSpec tabSpecApple = tabHost
      .newTabSpec("Apple")
      .setIndicator("Apple")
      .setContent(intentApple);

    // Windows tab
    Intent intentWindows = new Intent().setClass(this, WindowsActivity.class);
    TabSpec tabSpecWindows = tabHost
      .newTabSpec("Windows")
      .setIndicator("Windows")
      .setContent(intentWindows);

    // Blackberry tab
    Intent intentBerry = new Intent().setClass(this, BlackBerryActivity.class);
    TabSpec tabSpecBerry = tabHost
      .newTabSpec("Berry")
      .setIndicator("Berry")
      .setContent(intentBerry);

    // add all tabs 
    tabHost.addTab(tabSpecAndroid);
    tabHost.addTab(tabSpecApple);
    tabHost.addTab(tabSpecWindows);
    tabHost.addTab(tabSpecBerry);

    //set Windows tab as default (zero based)
    tabHost.setCurrentTab(2);
}

My Problem are the empty TabHosts after rotation, doesnt matter witch Tab is clicked nothing is displayed. Any hint?
Thanks

  • 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-10T22:56:50+00:00Added an answer on June 10, 2026 at 10:56 pm

    I thought to complex, there is no need to setContentView(R.layout.myLayout); or something else. Simply prevent a call of onCreate method by override onConfigurationChanged.

    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
    }
    

    this works for me.

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

Sidebar

Related Questions

I have problem with UpdateAllTasks activity. Before executing this activity, I have a task
I have problem with my query on C, I’m using the oci8 driver. This
I have problem while sending messages from android to PC. Messages are send when
i have problem with jquery submit and post. I would like to submit a
Have problem while getting data from Memcached on .NET MVC solution. I have this
I have problem with php's preg_match.I want to make something like this : When
I have problem like this https://dev.twitter.com/discussions/4563 if (webResponse.Headers[Content-Encoding] == gzip) { byte[] bytes =
Have problem with this code var MAIN_LOCATION = http://www.bosscaffe.com/new/; $(#gallery_page).click(function() { $('#gallery_photos').show(); getPhotos(); return
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a huge problem with the bump API on Android. I setup everything

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.