I have a webservice which is connecting to my server ok, as when i change it i get a true or false.
However no matter what the result it will redirect the page.
How do i do it so it redirects only when a true is returned?
my code is:
private final String NAMESPACE = "private final String URL = "
String user_id;
String password;
TextView logged;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.sign);
Button signin = (Button) findViewById(R.id.btnlogin);
signin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText etxt_user = (EditText) findViewById(R.id.txtuser);
user_id = etxt_user.getText().toString();
EditText etxt_password = (EditText) findViewById(R.id.txtpword);
password = etxt_password.getText().toString();
new LoginTask().execute();
}
});
}
private boolean doLogin(String user_id, String password) {
boolean result=false;
final String SOAP_ACTION = "final String METHOD_NAME = "LoginTest";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("userid", user_id);
request.addProperty("password",password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true; // Set this variable to true for
// compatibility with what seems to be the
// default encoding for .Net-Services.
envelope.setOutputSoapObject(request);
System.out.println(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp", response.toString());
System.out.println("response" +response);
if(response.toString().equalsIgnoreCase("successful"))
{
result = true;
}
}catch(SocketException ex)
{
//logged = (TextView)findViewById(R.id.logged);
logged.setText("Logged in ok");
Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
ex.printStackTrace();
}
catch (Exception e) {
//logged = (TextView)findViewById(R.id.logged);
//logged.setText("Unable to connect to server");
Log.e("Error : " , "Error on e.iveData() " + e.getMessage());
e.printStackTrace();
}
return result;
}
private class LoginTask extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(
Signin.this);
protected void onPreExecute() {
this.dialog.setMessage("Logging in...");
this.dialog.show();
}
protected Void doInBackground(final Void... unused) {
boolean auth=doLogin(user_id,password);
System.out.println(auth);
if (auth="1" != null)
{accessallowed(auth);}
return null;// don't interact with the ui!
}
protected void onPostExecute(Void result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
}
}
public void accessallowed(boolean auth)
{
Intent myintent = new Intent(this, MainActivity.class);
startActivity(myintent);
}
}
Supplier of Asset Financial Software
Web based, and pocket pc compatible
b3computing.co.uk
However no matter what the result it will redirect the page.
How do i do it so it redirects only when a true is returned?
my code is:
private final String NAMESPACE = "private final String URL = "
String user_id;
String password;
TextView logged;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.sign);
Button signin = (Button) findViewById(R.id.btnlogin);
signin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText etxt_user = (EditText) findViewById(R.id.txtuser);
user_id = etxt_user.getText().toString();
EditText etxt_password = (EditText) findViewById(R.id.txtpword);
password = etxt_password.getText().toString();
new LoginTask().execute();
}
});
}
private boolean doLogin(String user_id, String password) {
boolean result=false;
final String SOAP_ACTION = "final String METHOD_NAME = "LoginTest";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("userid", user_id);
request.addProperty("password",password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true; // Set this variable to true for
// compatibility with what seems to be the
// default encoding for .Net-Services.
envelope.setOutputSoapObject(request);
System.out.println(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp", response.toString());
System.out.println("response" +response);
if(response.toString().equalsIgnoreCase("successful"))
{
result = true;
}
}catch(SocketException ex)
{
//logged = (TextView)findViewById(R.id.logged);
logged.setText("Logged in ok");
Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
ex.printStackTrace();
}
catch (Exception e) {
//logged = (TextView)findViewById(R.id.logged);
//logged.setText("Unable to connect to server");
Log.e("Error : " , "Error on e.iveData() " + e.getMessage());
e.printStackTrace();
}
return result;
}
private class LoginTask extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(
Signin.this);
protected void onPreExecute() {
this.dialog.setMessage("Logging in...");
this.dialog.show();
}
protected Void doInBackground(final Void... unused) {
boolean auth=doLogin(user_id,password);
System.out.println(auth);
if (auth="1" != null)
{accessallowed(auth);}
return null;// don't interact with the ui!
}
protected void onPostExecute(Void result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
}
}
public void accessallowed(boolean auth)
{
Intent myintent = new Intent(this, MainActivity.class);
startActivity(myintent);
}
}
Supplier of Asset Financial Software
Web based, and pocket pc compatible
b3computing.co.uk