I'm doing my first project in android studio, using java, and I'm having a problem. The purpose of the program is to verify that the old password, in this case "xxxx", corresponds to the password typed by the app user. But when running the program, this comparison always gives error, even if it is the same. Can you help me, please?
package com.example.myapplication;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class ProfileActivity extends AppCompatActivity {
private EditText oldPass, newPass;
private Button buttonChange;
//private String oldPassstr, newPassstr; //tem a pass que o user vai inserir
//@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
newPass = (EditText) findViewById(R.id.editNewPassword);
oldPass = (EditText) findViewById(R.id.editOldPassword);
buttonChange = findViewById(R.id.change_but);
goToHome();
goToSmart();
ChangePassword(oldPass);
}
public void goToHome(){
ImageButton button = (ImageButton) findViewById(R.id.Profile_Home_but);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(ProfileActivity.this,myHomeActivity.class);
startActivity(i);
}
});
}
public void goToSmart(){
ImageButton button = (ImageButton) findViewById(R.id.Profile_Smart_but);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(ProfileActivity.this,SmartActivity.class);
startActivity(i);
}
});
}
public void ChangePassword(EditText oldPass) {
buttonChange.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (oldPass.getText().toString() == "xxxx") {
Context context1 = getApplicationContext();
Toast toast1 = Toast.makeText(getApplicationContext(), "Password Updated!", Toast.LENGTH_SHORT);
toast1.show();
}
else{
Context context2 = getApplicationContext();
Toast toast2 = Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_SHORT);
toast2.show();
}
}
});
}
}