1
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 + ")");
}
To MainActivity
sending two parameters(user and password) to the class LoginBackground
which checks through the class SistemaHttp
if there is a registered user with this data in the database. If there is one, the class SistemaHttp
returns to the doInBackground
a String to "OK".
So I wanted to take this String and pass it on to the MainActivity
to throw it in the way RetornoLogin()
and display a Toast according to the answer that came.
Obs: everything is working until the onPostExecute
, I put a Log() to display the doInBackground()
and it displays normal OK, just do not know proceed from then on.
To Asynctask is an inner class of Activity?
– ramaral
I’m sorry I’m a beginner in java(android) as well as activty internal?
– Bruno Romualdo
You mean if you’re in the same class?
– Bruno Romualdo
If not, I have a Mainactivity class (with the button) calling the other Loginbackground class (which extends Asynctask and has its respective methods from Background, onPostExecute) which checks if the user exists with the Systemshttp class. I don’t know if that’s what you asked me.
– Bruno Romualdo