reset password and save the new password in sharedpreference
I have, a screen in my app with a function to reset a password but I’m having trouble saving the value of edittext in sharedpreferences and recovering it returns a strange value someone could help me with what I’m doing wrong
this my screen
and this is what i tried to do i am sending this password to my main screen and saving it in sharedpreferences however when the value is recovered in my fragment it returns the following in logcat:
senhaandroidx.appcompat.widget.AppCompatEditText{3ad3e265 VFED..CL .F…… 15,300-739,375 #7f0a00dc app:id/edtConfirmaSenha}
code :
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment final View view = inflater.inflate( R.layout.fragment_redefinir_senha, container, false ); senha = view.findViewById( R.id.edtSenha); novasenha = view.findViewById( R.id.edtNovaSenha); confirmanovasenha = view.findViewById( R.id.edtConfirmaSenha); salvasenha = view.findViewById( R.id.btConfirma); prefs = Objects.requireNonNull(getContext()).getSharedPreferences("prefs", Context.MODE_PRIVATE); senhaatual = prefs.getString("novasenha", "1234"); return view; } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } @Override public void onResume() { super.onResume(); salvasenha.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d("TAG","senha" + senhaatual); if (senha.getText().toString().equals(senhaatual) && novasenha.getText().toString().equals(confirmanovasenha.getText().toString())) { editor = prefs.edit(); editor.putString("novasenha", ((novasenha.getText().toString()))); editor.apply(); Intent intent = new Intent(getActivity(), MainActivity.class); intent.putExtra( "key",confirmanovasenha.getText().toString()); startActivity(intent); } else { Toast.makeText(getActivity(), "NOVA SENHA INVALIDA", Toast.LENGTH_LONG).show(); } } }); }
}