Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Webservice - redirect on true return

Status
Not open for further replies.

Rowse

Technical User
Dec 20, 2002
62
GB
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
 
Q: are you able to filter the log in accounts that is only allowed to redirect?
IF SO: are you able to catch that? (like blocking if it has entered incorrect user and pass)

and thats how you can make it redirect if its NOT BLOCKED
also i am wondering, why did you use in your:
public void doInBackground()
{
boolean auth=doLogin(user_id,password);
System.out.println(auth);
if (auth="1" != null)
{
accessallowed(auth);
}
}
why did you compared "auth" to string "1" if its "BOOLEAN" ?
you may wanna check the LogCat to see whats happening on run time
theres a lot of asynctask guide over the net you might get an idea there
 
Thanks, i'd tried true/false in the auth= but still had the same result so was playing about with it to try and resolve.
The log cat shows that i am getting true and false back, but not sure where or how to use an if statement on "only redirect if the auth is true, if false show a message"

I've looked for it on the web but will have another look.

Supplier of Asset Financial Software
Web based, and pocket pc compatible
b3computing.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top