title: Transfer data between two activities
body: <p>I am trying to send and receive data between two different activities. I have seen some other questions asked on this site but no question has dealt with preserving the state of the first class.</p>
  
  <p>For example if I want to send an integer X to class B from class A then to do some operations on integer X and then send it back to class A, how does one go about doing this?</p>
  
  <p>Is it as simple as the following code?</p>
  
  <p>in Class A</p>
  
  <pre><code> Intent i = new Intent(this, ActivityB.class);
   i.putExtra("Value1", 1);
   startActivity(i);
  </code></pre>
  
  <p>and to receive the response from Class B:</p>
  
  <pre><code>Bundle extras = getIntent().getExtras();
  int value1 = extras.getint("Value1",0);
  </code></pre>
  
  <p>in Class B</p>
  
  <pre><code>Bundle extras = getIntent().getExtras();
  int value1 = extras.getint("Value1",0);
  //Do some operations on value1 such as maybe adding or subtracting
  Intent i = new Intent(this, ActivityA.class);
  i.putExtra("Value1", 1);
  startActivity(i);
  </code></pre>
  
  <p>This does not seem correct as I simply want to switch back to Activity A and receive the data from Activity B once the action is completed (perhaps a button in Activity B commences operations on the received data and then sends it back to Activity A?)</p>