Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just so that I am clear, are you saying that you have several tabs, which are using different orientations (portrait or landscape), and you are having issues when switching tabs and setting the corresponding orientations properly?</p> <p>In response to Cata's comment:</p> <p>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.</p> <p>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.</p> <p>Does that make sense?</p> <p>Keep in mind that I have not tested that, but willing to do so if you aren't familiar with those two method calls.</p> <p>Below is an example of saving data to the Bundle - also recall that onCreate accepts that activity bundle as a parameter.</p> <pre><code>@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 &gt; 0) elapsedTime = elapsed; int theOrientation = savedInstanceState.getInt("Orientation"); //if(theOrientation &gt; 0) //this.setRequestedOrientation(theOrientation); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload