title: How to reuse a method from a different class
body: <p>I have an authenticateID method which searches in the database to find a match and does something. I guess it will take long to explain so here is my code:</p>
  
  <pre><code>public boolean authenticateStudentID() {
  
      boolean success = true;
  
      final String studentID = etStudentID.getText().toString().trim();
      final String module = etModule.getText().toString().trim();
      final String degree = etDegree.getText().toString().trim();
      final String room = etRoom.getText().toString().trim();
      final String email = etEmail.getText().toString().trim();
      final String fullname = etfullname.getText().toString().trim();
      final String loginID = etLoginID.getText().toString().trim();
  
      if (success) {
          databaseRef.addListenerForSingleValueEvent(new ValueEventListener() {
              public void onDataChange(DataSnapshot dataSnapshot) {
                  for (DataSnapshot snapshot : dataSnapshot.getChildren()) { // wtf is this advanecd for loop
                      //map string string because our key is a string and value is a string, map has a key and value object
                      Map&lt;String, String&gt; map = (Map) snapshot.getValue();
                      if (map != null) { //if the values and keys are not null
                          String studentIDMatch = map.get("studentID");
  
                        //  Log.v("E_VALUE", "students ID entered : " + studentIDMatch);
                        //  Log.v("E_VALUE", "students ID from db: " + studentID);
                          if (studentID.equals(studentIDMatch)) {
                              String uniqueKey = databaseRef.push().getKey();
  
                              NewStudentAccounts sam = new NewStudentAccounts
                                      (studentID, loginID, email, fullname, module, degree, room);
  
                              databaseRef.child(uniqueKey).setValue(sam);
  
                              Toast.makeText(getApplicationContext(), "Your account registration has been successful!", Toast.LENGTH_SHORT).show();
                              startActivity(new Intent(getApplicationContext(), LoginActivity.class));
                          } else {
                              Toast.makeText(getApplicationContext(), "Invalid Student Credentials Entered!!", Toast.LENGTH_SHORT).show();
                          }
                      }
                  }
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
              }
          });
      }
      return success;
  </code></pre>
  
  <p>I want to know how I can reuse this method for another class instead of copy and pasting code. Please guide me, I really appreciate it. </p>
  
  <pre><code>private void addNewStudent() {
  
      findViewById(R.id.buttonAddStudent).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
  
              View addStudentActivityDialog = LayoutInflater.from(LecturerAccount.this).inflate(R.layout.activity_add_student,null);
  
              etStudentName = addStudentActivityDialog.findViewById(R.id.editTextStudentName);
              etStudentUserID = addStudentActivityDialog.findViewById(R.id.editTextStudentUserID);
  
              AlertDialog.Builder addStudentBuilder = new AlertDialog.Builder(LecturerAccount.this);
  
              addStudentBuilder.setMessage("STAR").setView(addStudentActivityDialog).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                      String studentName = etStudentName.getText().toString();
                      String studentID = etStudentUserID.getText().toString();
  
                      registerActivity = new RegisterActivity(); //calling the instance of the class here
  
                      if (registerActivity.authenticateStudentID() == true){
                          studentarray.add(studentName);
                      }
  
                  }
              }).setNegativeButton("cancel", null).setCancelable(false);
              AlertDialog newStudentDialog = addStudentBuilder.create();
              newStudentDialog.show();
          }
      });
  
  }
  </code></pre>
  
  <p>My if statement here calling the function, I am totally clueless here.</p>