title: Android: Exit full screen and return to main activity
body: <p>Main activity contains a spinner and a button. MainActivity.java code is as follows.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public class MainActivity extends AppCompatActivity implements LoadNew.VCallback {
  
      public Spinner dropdown;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          dropdown = (Spinner) findViewById(R.id.spinner1);
  
          //Create a list of items for the spinner.
          String[] items = new String[]{"select topic", "topic1", "topic2"};
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, items);
          dropdown.setAdapter(adapter);
          dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parentView, View selectedItemView, int position, long id) {
                  // TODO Auto-generated method stub
                  String sp1 = String.valueOf(dropdown.getSelectedItem());
                  if (sp1.contentEquals("select topic")) {
                      loadFun("");
                  }
                  if (sp1.contentEquals("topic1")) {
                      loadFun("topic1");
                  }
                  if (sp1.contentEquals("topic2")) {
                      loadFun("topic2");
                  }
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; parentView){
                  // TODO Auto-generated method stub
              }
          });
  
          Button x = (Button) findViewById(R.id.full_screen);
          x.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  loadFun("topic2", 0);
              }
          });
      }
  
      public void loadFun(String topicName, int i) {
          LoadNew st = new LoadNew(this);
          st.display(topicName, i);
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The xml layout for main activity is as follows (activity_main.xml).</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"&gt;
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal" &gt;
              &lt;Spinner
                  android:id="@+id/spinner1"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:background="@android:drawable/btn_dropdown"
                  android:spinnerMode="dropdown" /&gt;
          &lt;/LinearLayout&gt;
          &lt;LinearLayout
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:orientation="horizontal" &gt;
               &lt;Button
                  android:id="@+id/full_screen"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="Full Screen"
                  style="?android:attr/borderlessButtonStyle"/&gt;
          &lt;/LinearLayout&gt;
          &lt;LinearLayout
              android:id="@+id/full_view"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal" &gt;
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  &lt;/RelativeLayout&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>There is another java class LoadNew.java as follows.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public class LoadNew {
  
      public interface VCallback {
          //To access methods of MainActivity class
      }
  
      public Activity activity;
  
      public LoadNew(Activity _activity) {
          this.activity = _activity;
          VCallback callerActivity = (VCallback) activity;
  
      }
  
      //Display PDF
      public void display(String topicName, int i) {
          LinearLayout fullScreen = (LinearLayout) this.activity.findViewById(R.id.full_view);
          fullScreen.removeAllViews();//Clear field
          LayoutInflater inflater = (LayoutInflater) this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          View view = inflater.inflate(R.layout.activity_load, null);
          if(i ==0) {
           this.activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
              this.activity.setContentView(view);
          }
          TextView tv= (TextView) this.activity.findViewById(R.id.tv1);
          tv.setText(topicName);
          tv.setTextSize(100);
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>The activity_load.xml file is as follows.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout&gt; xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity"&gt;
  
  &lt;TextView
      android:id="@+id/tv1"
      android:layout_below="@+id/bar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/&gt;
  
  &lt;/RelativeLayout&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>When an item is selected in the spinner, the corresponding text is displayed in the textview. Upon pressing the button, the textview appears in full screen mode. 
  Now I want to return to the previous view (by pressing back button or by single tab on screen), i.e., the view before the button was clicked. How can I achieve this? Thanks in advance for the patience and the help. </p>