title: Passing values between activity
body: <p>I should show 2 <code>TextView</code> in <code>MainActivity</code> "stringadaA" and "numerodaB" , namely the string and the number put in the 2 activities A and B.These values must not be lost in the transition between the activities but must change only when they are changed by the user. I managed to do it but when I press the "Ritorna" button to go back to the <code>MainActivity</code> it does not  maintain both the results as I would expect, why are not both saved if I insert  values in <code>ActivityA</code> and <code>ActivityB</code>?</p>
  
  <p>Thanks in advance</p>
  
  <pre><code>public class MainActivity extends Activity {
      TextView stringaA;
      TextView numeroB;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          stringaA = findViewById(R.id.stringadaA);
           numeroB= findViewById(R.id.numerodaB);
          Button btnA = findViewById(R.id.btnactivitya);
          Button btnB= findViewById(R.id.btnactivityb);
          final EditText editText= findViewById(R.id.editactivitya);
          btnA.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent i = new Intent(getApplicationContext(), ActivityA.class);
                  startActivity(i);
              }
          });
          Bundle extras= getIntent().getExtras();
          if (extras!=null){
              String value = extras.getString("stringaA");
              String number =extras.getString("numero");
              stringaA.setText(value);
              numeroB.setText(number);
          }
  
          btnB.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent i = new Intent(getApplicationContext(), ActivityB.class);
                  startActivity(i);
  
              }
          });
  
      }
  
      @Override
      protected void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          String stringa= stringaA.getText().toString();
          outState.putString("STRINGA", stringa);
      }
  
      @Override
      protected void onRestoreInstanceState(Bundle savedInstanceState) {
          super.onRestoreInstanceState(savedInstanceState);
          String stringa= savedInstanceState.getString("STRINGA");
  
      }
  }
  
  </code></pre>
  
  <pre><code>public class ActivityA extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_a);
  
          final EditText edtA= findViewById(R.id.editactivitya);
          Button returnbtnA= findViewById(R.id.ritornaallaprincipaleA);
          returnbtnA.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                 Intent i = new Intent(getApplicationContext(), MainActivity.class);
                 i.putExtra("stringaA", edtA.getText().toString());
                 startActivity(i);
  
              }
          });
      }
  }
  </code></pre>
  
  <pre><code>public class ActivityB extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_b);
  
          final EditText edtb= findViewById(R.id.editactivityb);
          Button returnbtnb= findViewById(R.id.ritornaallaprincipaleB);
          returnbtnb.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent i = new Intent(getApplicationContext(), MainActivity.class);
                  i.putExtra("numero", edtb.getText().toString());
                  startActivity(i);
              }
          });
      }
  }
  
  </code></pre>
  
  <p>XML CODE</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity"&gt;
  
   &lt;TextView
       android:id="@+id/testo1"
       android:textSize="30dp"
       android:layout_marginTop="30dp"
       android:layout_centerHorizontal="true"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Main Activity"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintTop_toTopOf="parent" /&gt;
  
   &lt;Button
           android:id="@+id/btnactivitya"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginTop="30dp"
           android:textSize="20dp"
           android:text="Activity A"
           android:layout_below="@+id/testo1"
           android:layout_centerHorizontal="true"
       /&gt;
   &lt;Button
       android:id="@+id/btnactivityb"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginTop="30dp"
       android:textSize="20dp"
       android:text="Activity B"
       android:layout_below="@+id/btnactivitya"
       android:layout_centerHorizontal="true"/&gt;
  
   &lt;TextView
       android:id="@+id/stringaA"
       android:layout_below="@id/btnactivityb"
       android:layout_width="wrap_content"
       android:layout_marginTop="30dp"
       android:layout_centerHorizontal="true"
       android:layout_height="wrap_content"
       android:text="Stringa da Activity A:"/&gt;
  
   &lt;TextView
       android:id="@+id/stringadaA"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_below="@+id/stringaA"
       android:layout_centerHorizontal="true"
       android:textSize="20dp"
       android:layout_marginTop="30dp"/&gt;
   &lt;TextView
       android:id="@+id/stringaB"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
      android:text="Numero da Activity B"
       android:layout_marginTop="20dp"
       android:layout_below="@+id/stringadaA"
       android:layout_centerHorizontal="true"/&gt;
   &lt;TextView
       android:id="@+id/numerodaB"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_below="@+id/stringaB"
       android:layout_centerHorizontal="true"
       android:layout_marginTop="20dp"
       android:textSize="20dp"
   /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;TextView
          android:id="@+id/ActivityA"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="30dp"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="40dp"
          android:text="Activity A"/&gt;
      &lt;TextView
          android:id="@+id/InserisciA"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="90dp"
          android:layout_centerInParent="true"
          android:textSize="20dp"
          android:layout_below="@+id/ActivityA"
          android:text="Inserisci stringa"/&gt;
      &lt;EditText
          android:id="@+id/editactivitya"
          android:layout_marginTop="20dp"
          android:layout_below="@+id/InserisciA"
          android:layout_centerHorizontal="true"
          android:layout_width="wrap_content"
          android:width="100dp"
          android:layout_height="wrap_content" /&gt;
  
      &lt;Button
          android:id="@+id/ritornaallaprincipaleA"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/editactivitya"
          android:layout_alignStart="@+id/InserisciA"
          android:layout_marginStart="3dp"
          android:layout_marginTop="25dp"
          android:text="Ritorna"
          android:textSize="20dp" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;TextView
          android:id="@+id/ActivityB"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="30dp"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="40dp"
          android:text="Activity B"/&gt;
      &lt;TextView
          android:id="@+id/InserisciB"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="20dp"
          android:layout_centerHorizontal="true"
          android:layout_centerInParent="true"
          android:layout_below="@+id/ActivityA"
          android:text="Inserisci numero"/&gt;
      &lt;EditText
          android:id="@+id/editactivityb"
          android:layout_below="@+id/InserisciB"
          android:layout_centerHorizontal="true"
          android:width="100dp"
          android:layout_marginTop="20dp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
      &lt;Button
          android:id="@+id/ritornaallaprincipaleB"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Ritorna"
          android:textSize="20dp"
          android:layout_marginTop="40dp"
          android:layout_centerHorizontal="true"
          android:layout_below="@+id/editactivityb"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>