0

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?

blankon91
  • 521
  • 3
  • 15
  • 39
  • 2
    Don't EVER compare Strings using ==, use `someString.equals(anotherString)`, instead of `hasil == "START"` do `hasil.equals("START")` – Austin Jun 18 '12 at 08:22
  • 1
    I would suggest you to use JSON http://www.json.org/ 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 – Cata Jun 18 '12 at 08:23
  • @Austin thank you for your advice :) I'll do it.. – blankon91 Jun 18 '12 at 08:31
  • @Cata Okay, I'll search how to user json for parsing the value from .NET web service for my android aplication..Thank you for your suggestion..but is there another way? or is JSON the best one? – blankon91 Jun 18 '12 at 08:31
  • 1
    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 – Cata Jun 18 '12 at 08:35
  • @Cata okay, I think I will use JSON..thank you very much :) if I get trouble when using JSON, I will ask again :) – blankon91 Jun 18 '12 at 08:47
  • 1
    `hasil == "START"` this is not correct, you should use `hasil.equals("START")` instead of yours. When you comparing `Strings`, you have to use `equals()`, not `==` this is not very good, safe etc. – Simon Dorociak Jun 18 '12 at 08:26

1 Answers1

1

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.

Cata
  • 11,133
  • 11
  • 65
  • 86
  • hai @Cata, I've follow your advice, but I've problem to put my result from the JSON parsing method into my return statement. can you help me right [here](http://stackoverflow.com/q/11093355/1160352) – blankon91 Jun 19 '12 at 01:52