title: Calling method in main activity when a variable is changed in dialog box
body: <p>I have listed the code below, What i am trying to achieve is the int i to be updated from a dialog box (dialog2). I then want to check in the main activity if it has changed and if it has changed then call a method. How would i do this?</p>
  
  <p>Main Activity</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      int i = 0;
  
  
      Dialog1 dialog1 = new Dialog1(this, i);
      dialog1.show();
  }
  
  //Want to call this method whenever I is modified
  private void iModified(){
  
  }
  }
  </code></pre>
  
  <p>Dialog 1 Class (This dialog just passes it to dialog2)</p>
  
  <pre><code>public class Dialog1 extends Dialog{
  
  int integerI;
  Button button;
  
  
  public Dialog1(final Activity activity, final int i){
      super(activity);
      setContentView(R.layout.dialog1);
      integerI = i;
  
      button = findViewById(R.id.dialog1Button);
  
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Dialog2 dialog2 = new Dialog2(activity ,integerI);
              dialog2.show();
              closeDialog();
          }
      });
  
  }
  
  private void closeDialog(){
      this.dismiss();
  }
  
  }
  </code></pre>
  
  <p>Dialog 2: This is where the integer is going to be changed and then i want it to be sent to the main activity and checked if it has changed and if so then replace the old integer with the new one.</p>
  
  <pre><code>public class Dialog2 extends Dialog {
  
  int newI;
  Button button;
  
  public Dialog2(Activity activity, int i) {
      super(activity);
      setContentView(R.layout.dialog2);
      newI= i + 12345;
  
  
      button = findViewById(R.id.dialog2Button);
  
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              close();
  
                  }
      });
  
  
  }
  
  private void close(){
      this.dismiss();
  }
  }
  </code></pre>