title: Saving Activity State when switching activities
body: <p>I'm currently trying to create an activity, which should be creating a new TextView on my main activity, everytime a Button is clicked on the first activity. However, instead of creating a new TextView everytime the button is clicked, it just changes the values of the first created TextView, so that there is always only one TextView. Is there a way to make it so that my first activity will not only create one single textview? </p>
  
  <p>Here's the code from my "NewSubjectActivity": </p>
  
  <pre><code>**public class NewSubjectActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_new_subject);
  
      Button SaveBtn = findViewById(R.id.SaveBtn);
      nsaSaveBtn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Click();
          }
      });
  }
  
  
  
  protected void Click(){
  
      Intent intent = new Intent(NewSubjectActivity.this, MainActivity.class);
  
      Boolean createnewTextView = true;
  
      intent.putExtra("createnewTextView",createnewTextView);
      startActivity(intent);
  }
  
  }
  </code></pre>
  
  <p>And here's the (relevant) code from my MainActivity: </p>
  
  <pre><code> protected void ReceiveValue (){
  
  
      //getting Extras
      Intent nsareceivedvalues = getIntent();
  
  
          boolean createTextView = false;
          createTextView = nsareceivedvalues.getExtras().getBoolean("createnewTextView");
  
          //declaring fixed Views
          final LinearLayout mainLinearLayout = (LinearLayout)findViewById(R.id.mainLinearLayout);
  
  
  
  
          //Params for TextView
          RelativeLayout.LayoutParams Params = new RelativeLayout.LayoutParams(1000, 200);
          Params.setMargins(0, 10, 0, 10);
  
          while(createTextView) {
              //creating a TextView
              TextView newsubject = new TextView(MainActivity.this);
  
              //applying values to the TextView
              newsubject.setLayoutParams(Params);
              newsubject.setGravity(CENTER);
              newsubject.setBackgroundColor(Color.GRAY);
  
              mainLinearLayout.addView(newsubject);
              createTextView = false; 
          }
  
  }
  </code></pre>
  
  <p>As I said, this only create one text view, everytime I press the button on my "NewSubjectActivity" I think this might be, because the previous text view is not saved and the MainActivity is reset everytime I switch between the activities. </p>
  
  <p>Every help and advise is much appreciated &lt;3</p>