title: Second Activity's' button jump back to Main Activity which it shouldn't be
body: <p>I am new at Android development for my final year project. I have encounter some problem that second activity which is Parent Login Activity Page submit button is not working well as it should be done error checking before moving to another activity page.</p>
  <p><strong>Main Activity.java code</strong></p>
  <pre><code>public class MainActivity extends AppCompatActivity implements View.OnClickListener{
  //DEFINE WHICH BUTTON TO CLICK ON
  Button ButtonParent;
  Button ButtonKid;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      ButtonParent=findViewById(R.id.buttonParent);
      ButtonKid=findViewById(R.id.buttonKid);
      ButtonParent.setOnClickListener(this);
      ButtonKid.setOnClickListener(this);
  }
  @Override
  public void onClick(View view) {
          if (view==ButtonParent) {
              Intent intent_Parent = new Intent(MainActivity.this, ParentLogin.class);
              intent_Parent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent_Parent);
          }else if(view==ButtonKid) {
              Intent intent_Kid = new Intent(MainActivity.this, KidLogin.class);
              intent_Kid.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent_Kid);
          }
      }
  }
  </code></pre>
  <p><strong>Parent Login.java Code</strong></p>
  <pre><code>public class ParentLogin extends AppCompatActivity implements View.OnClickListener{
  EditText pName;
  EditText pNRIC;
  Button ParentLogin;
  Button ParentRegister;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_parent_login);
  
      pName = findViewById(R.id.LoginParentName);
      pNRIC = findViewById(R.id.ParentNRIC);
  
      ParentLogin=findViewById(R.id.LoginParentSubmit);
      ParentRegister=findViewById(R.id.LoginParentRegister);
      ParentLogin.setOnClickListener(this);
      ParentRegister.setOnClickListener(this);
  }
  @Override
  public void onClick(View view) {
      if (view == ParentLogin) {
  
          String ParentName = pName.getText().toString().trim();
          String ParentNRIC = pNRIC.getText().toString().trim();
          boolean res = ParentDAO.checkParent(ParentName, ParentNRIC);
          if ((TextUtils.isEmpty(ParentName))||!(TextUtils.isEmpty(ParentNRIC))) {
              Toast toast= Toast.makeText(ParentLogin.this, &quot;Please fill in all the empty columns which are available&quot;, Toast.LENGTH_SHORT);
              toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL,0,0);
              toast.show();
  
          } else {
              if (res) {
                  Toast.makeText(ParentLogin.this, &quot;Login Successfully&quot;, Toast.LENGTH_SHORT).show();
                  Intent intent_parentActivity = new Intent(ParentLogin.this, ParentActivity.class);
                  intent_parentActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  startActivity(intent_parentActivity);
              } else {
                  Toast.makeText(ParentLogin.this, &quot;Login not Successfully&quot;, Toast.LENGTH_SHORT).show();
              }
          }
      }else if(view==ParentRegister) {
          Intent intent_parentRegister = new Intent(ParentLogin.this, ParentRegistration.class);
          intent_parentRegister.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          startActivity(intent_parentRegister);
      }
  }
  }
  
                          
  </code></pre>