I’ve made .NET web service, so far my android application can communicate with my web service. Now, I want to make a login form, and I’m confuse with the values from my web service.
Here is my code for login:
// Login button Click Event
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
try
{
inputUser = (EditText) findViewById(R.id.loginUser);
inputPassword = (EditText) findViewById(R.id.loginPassword);
String user = inputUser.getText().toString();
String password = inputPassword.getText().toString();
hasil = "START";
Panggil call = new Panggil();
call.user = user;
call.password = password;
call.join();
call.start();
while (hasil.equals("START")){
try{
Thread.sleep(10);
}
catch (Exception ex){
}
}
if (hasil != ""){
loginErrorMsg.setText("");
// Launch Dashboard Screen
// Send User Full Name to Dashboard Screen
Intent dashboard = new Intent(getApplicationContext(), DashboardActivity.class);
dashboard.putExtra("myname", hasil);
// Close all views before launching Dashboard
dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(dashboard);
// Close Login Screen
finish();
}
else{
// Error in login
loginErrorMsg.setText("Incorrect username/password");
}
}
catch(Exception ex)
{
ad.setTitle("Error!");
ad.setMessage(ex.toString());
ad.show();
}
}
});
From that login code, I get the value for hasil like this:
anyType{ccduser=myusername; password=123456}
How to extract or parsing that value and use it for IF..ELSE.. condition for login?
I will put this as an answer..
I would suggest you to use JSON to pass data from ws to client and back, there are a lot of free library on the internet for .NET and android.. also Android has JSON parser API integrated
You can use also XML but for mobile I would recomand JSON because it is more lighter and you can find a lot of libraries for it.. You can also develop your own data encapsulation format but it will take some time and if you would want in the future to make your client app to work with other servers or your server to send data to other clients you will have to get back and use some standards like JSON or XML.