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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:03:14+00:00 2026-06-11T14:03:14+00:00

Hi i have an issue with an android app i’m building the app uses

  • 0

Hi i have an issue with an android app i’m building the app uses tabs once a tab is clicked it starts an activity the problem arises if i rotate the screen the app goes back to the default tab. I would like on rotate for the current tab to be retained here is my code and where i’ve gotten i saw a similar question on this but the solutions there were not able t help me so please an example would really help me

    import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MultiLingualDictionaryActivity extends Activity   {
    /** Called when the activity is first created. */
    private String TAB_TAG,TAB_TAG2,TAB_TAG3;
    TabHost tabHost;
    LocalActivityManager mlam;  
    private int CurrentTab = 1 ;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main_tabs);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
        TAB_TAG = this.getString(R.string.search);
        TAB_TAG2 = this.getString(R.string.more);
        TAB_TAG3 = this.getString(R.string.history);
         mlam = new LocalActivityManager(this, false);
         tabHost = (TabHost) findViewById(R.id.tabhost);
         mlam.dispatchCreate(savedInstanceState);
         tabHost.setup(mlam);

         TabSpec spec1=tabHost.newTabSpec(TAB_TAG);
         spec1.setIndicator(TAB_TAG,getResources().getDrawable(R.drawable.search));
         Intent in1=new Intent(this, ManageTab.class);
         spec1.setContent(in1);

         TabSpec spec4=tabHost.newTabSpec(TAB_TAG2);
         spec4.setIndicator(TAB_TAG2,getResources().getDrawable(R.drawable.more));
         Intent in4=new Intent(this,MoreActivity.class);
         spec4.setContent(in4);

         tabHost.addTab(spec1);
         tabHost.addTab(tabHost.newTabSpec(TAB_TAG3)
                .setIndicator(TAB_TAG3,getResources().getDrawable(R.drawable.history))
                .setContent(new Intent(this, ManageTab2.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
         tabHost.addTab(spec4);

        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
        getLastNonConfigurationInstance(); 
         super.onCreate(savedInstanceState);  

        tabHost.setCurrentTab(CurrentTab);
        tabHost.setOnTabChangedListener(tabhostListener);
    }
    TabHost.OnTabChangeListener tabhostListener =  new TabHost.OnTabChangeListener(){
        public void onTabChanged(String tabId) {
            if(TAB_TAG.equals(tabId)) {

                CurrentTab = tabHost.getCurrentTab();
                System.out.println(CurrentTab);
            }
            else if(TAB_TAG2.equals(tabId)) {
                CurrentTab = tabHost.getCurrentTab();
                System.out.println(CurrentTab);
            }
            else{
                CurrentTab = tabHost.getCurrentTab();
                System.out.println(CurrentTab);
            //mlam.destroyActivity(TAB_TAG3, true);
             //   mlam.startActivity(TAB_TAG3, new Intent(getApplicationContext(),ManageTab2.class));
            //System.out.println("destroy tab2");
        }
    }
};

/*@Override
protected void onStart(){
    tabHost.setCurrentTab(CurrentTab);
}*/


@Override
public Object onRetainNonConfigurationInstance(){
    CurrentTab = tabHost.getCurrentTab();
        return CurrentTab;

}
}
  • 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-11T14:03:16+00:00Added an answer on June 11, 2026 at 2:03 pm

    When the orientation of your application changes, it calls the onCreate method again. What you can do is add the tab index to your savedInstanceState variabel when your user changes tab.
    Then in oncreate you can check if your tabindex is set, if so, show the correct tab.

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

Sidebar

Related Questions

I have an issue related publishing the paid app to android market. (My application
I have an Android App with a number of activities. The wrong activity is
I have accomplished developing an android app that uses the facebook sdk to integrate
I have a real newbie issue. I have recently uploaded my first android app,
I have an Issue with Android 4 (ICS) My Bluetooth-App connecting to a Serial
i have a issue with programming for android. i have a string like this:
I have an issue that when I leave the android device idle for a
I have an issue with importing a picture from the Album in Android, because
I have a very specific SSL issue on my Android. If I try to
Hi I am new to android and I am having an issue I have

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.