I have this code:
MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String user = txt_usuario.getText().toString();
final String pssw = txt_senha.getText().toString();
//progressBar.setVisibility(View.VISIBLE);
LoginBackground lb = new LoginBackground();
lb.execute(user, pssw);
}
});
}
private void retornoLogin(String ret) {
if (ret.equals("OK"))
{
Toast.makeText(this, "Logado com sucesso", Toast.LENGTH_SHORT).show();
}
else if (ret.equals("ERRO"))
{
Toast.makeText(this, "Login incorreto", Toast.LENGTH_SHORT).show();
}
}
And this:
LoginBackground:
@Override
protected String doInBackground(String... params) {
String p1 = params[0];
String p2 = params[1];
SistemaHttp sHttp = new SistemaHttp(null);
String logado = sHttp.retornaUsuario(p1, p2);
return logado;
}
@Override
protected void onPostExecute(String str)
{
Log.d("TESTE","(LoginBackground) onPostexecute(" + str + ")");
}
MainActivity
is sending two parameters (user and password) to class LoginBackground
that checks through class SistemaHttp
if there is a user registered with that data in the database. If it exists, the class SistemaHttp
returns to doInBackground
a String to "OK".
So I wanted to get this String and pass it to MainActivity
to play it in RetornoLogin()
method and display a Toast according to the answer that came.
Note: this is all working up to onPostExecute
, I put a Log () to display the return string of the doInBackground()
and it shows OK normal, I just do not know to continue thereafter.