I am calling a webservice using doInBackgroung methode in a service using this code
public class LoginService {
public int status;
private String _login;
private String _pass;
public HttpResponse response;
public LoginService(String log, String pass) {
_login = log;
_pass= pass;
authenticate();
}
private void authenticate() {
new RequestTask().execute("http://safedrive.url.ph/v1/login?email="+_login+"&password="+_pass);
}class RequestTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... uri) {
Log.e("Login","******Login Started************");
HttpClient httpclient = new DefaultHttpClient();
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
status = statusLine.getStatusCode();
} else {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (Exception e) {
e.printStackTrace();
}
Log.e("reponse", responseString);
return responseString;
}
@Override
protected void onPostExecute(String responseString) {
Log.e("status",""+ status);
//when i execute my code with right values of password and address,status gets the right value (200) and i can loggout it
super.onPostExecute(responseString);
}
Then I call the service in my main activity after a click button
connectButton.setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
address = ADDRESS.getText().toString();
pwd = PASS.getText().toString();
LoginService logService = new LoginService(address,pwd);
Log.e("service", logService.getStatus()+"");// here the value of logService.getStatus() is 0 !!
if (logService.getStatus()==200 )
{
Intent intent = new Intent(MainActivity.this,WelcomeActivity.class);
startActivity(intent);
}
else {Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_LONG).show();}
}
});
The value of status is not changed in the main activity so I can't pass to the other activity.