title: Is there a way to have a separate class control a button on Main Activity class (Android Studio)
body: <p>I have a class main activity (code show below) that controls the button on a screen of an app I am developing. I have a separate class named SQL which in theory would take the information inputted in the screen and pass it into a database. How would I make it so that the SQL class responds to the button being pressed in main activity and pass the info collected in Main Activity to the database via SQL Query. Would the class SQL need to extend Main Activity and have an onclicklistner?</p>
  <pre><code>import android.content.Intent;
  import android.os.Bundle;
  
  import com.google.android.material.floatingactionbutton.FloatingActionButton;
  import com.google.android.material.snackbar.Snackbar;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.appcompat.widget.Toolbar;
  import android.view.View;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.Button;
  
  public class MainActivity extends AppCompatActivity{
      public Button mainScreen;
      public Button signIn;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          mainScreen = findViewById(R.id.createAccountButtonMain);
          mainScreen.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(MainActivity.this, Create_Account.class );
                  startActivity(intent);
              }
          });
          signIn = findViewById(R.id.signInButton);
          signIn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(MainActivity.this, HomeScreen.class);
                  startActivity(intent);
              }
          });
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
      // Comment
  }
  </code></pre>