Android TabActivity and Orientation change?

Use the android:configChanges="orientation attribute in manifest file like below.

Use the android:configChanges="orientation" attribute in manifest file like below.

I forgot to write that I don't want to use configChanges, please read under EDIT in the post. Thank you for trying to help aniway. – Cata Nov 4 at 13:40 why can't you use config changes?

If you add config changes to the tab activity for orientation. Do not add the screenOrientation to your xml so that it can rotate if your xml is setup properly then the tabs will rotate to landscape. In your activity you can use onConfigurationChange to switch your layout if you need to.

I can add an answer with what I mean as well. – caguilar187 Nov 13 at 5:24 My app is changing the rotation.. I don't have screenOrientation on my manifest file. – Cata Nov 13 at 20:57.

In response to Cata's comment: Yes, so anytime you rotate the screen the currently viewable activity is destroyed and onCreate is called again (if I recall the steps). What you have to do is call getCurrentTab(), which returns the int value representing the tab, and resetting that as the active tab when onCreate is called. You can do this in several ways...either by having a small method that handles just that and calling it via onCreate, or by using onSaveInstanceState(Bundle) to save your current data, and onRestoreInstanceState() to reload your tab data.

You can set a global int (int currentTab = 0), not setting it in onCreate(), and in your onSaveInstanceState(Bundle) method you can save that to the current tab (currentTab = getCurrentTab()), then in onRestoreInstanceState() you can set it again. Does that make sense? Keep in mind that I have not tested that, but willing to do so if you aren't familiar with those two method calls.

Below is an example of saving data to the Bundle - also recall that onCreate accepts that activity bundle as a parameter. @Override public void onSaveInstanceState(Bundle outState){ // Store UI state to the savedInstanceState. // This bundle will be passed to onCreate on next call.

Super. OnSaveInstanceState(outState); String strMinSec = timer.getText().toString(); String strMs = timerMs.getText().toString(); long curElapstedTime = elapsedTime; boolean timerStopped = stopped; int orientation = this.getResources(). GetConfiguration().

Orientation; outState. PutString("MinSec", strMinSec); outState. PutString("Ms", strMs); outState.

PutLong("Elapsed", elapsedTime); outState. PutBoolean("Stopped", timerStopped); outState. PutInt("Orientation", orientation); } @Override public void onRestoreInstanceState(Bundle savedInstanceState){ // Restore UI state from the savedInstanceState.

If (savedInstanceState! = null){ String MinSec = savedInstanceState. GetString("MinSec"); if (MinSec!

= null) { timer. SetText(MinSec); } String Ms = savedInstanceState. GetString("Ms"); if (Ms!

= null) { timerMs. SetText(Ms); } long elapsed = savedInstanceState. GetLong("Elapsed"); if(elapsed > 0) elapsedTime = elapsed; int theOrientation = savedInstanceState.

GetInt("Orientation"); //if(theOrientation > 0) //this. SetRequestedOrientation(theOrientation); } }.

I have 4 tabs that are using the same orientation.. but if the user wants to switch to landscape he can simply rotate the phone and the rotation is managed by android.. So I want my tab activity to be compatible with both orientations, it seems that the problem comes when I select any tab but the first one and then I rotate the device, the tab activity gets killed and after is recreating is setting the first tab as the selected tab and right after that it kills the first tab and make visible the real selected tab. I hope now it's more clear :) – Cata Nov 12 at 13:00 Hmm, thank you for trying to help me. The problem is that I know how to get the selected tab, what I don't know is how can I change the tab from the tabActivity without letting the TabHost to set first the first tab and after that my selected tab... if I try to call setCurrentTab(2) for example, the tabactivity first calls the first's tab onCreate() method and only after that is calling the selected tab's onCreate() method... – Cata Nov 13 at 16:24.

I think the best solution is to take a different approach by using a single Activity and put every tab content in a different LinearLayout and in onClick() methods of the tabs(which will be some buttons) to switch between the layouts... If anybody have a better idea, please post it here! Thank you!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions