This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
What do you have so far, and where are you stuck making progress? Communication with the server can be handled by the HttpClient library that is part of the Android API. You should use HTTPS, or encrypt or hash the password before sending it to the server, so that it's not sent in cleartext over the wires.
D. Capri Michael
Joined: Jan 16, 2011
Oh mainly i just designed the UI. I m stuck at how/which to use for the communication with the server as i did some research over the get/post http method and also json but still not quite sure about it. @@
I found a really useful blog for this. It has a sample login android application which sends the user name and the password to a remote server to validate. the server is a simple servlet application. It validates and sends the response back to android app.. It looks really simple and the below page contains complete code as well... Please go through.. Hope this would be helpful...
Hi Prabu, the code there leaves a lot to be desired. First, as Tim Moores said, you should not be sending the password out in the free/open like you are. You should be hashing or using HTTPS.
Second, in your OnClickListener you have code which starts a new Thread and uses that Thread to post the login to the server and wait for the response. You then, outside the Thread, immediately get the response to do something with. This is not good. It is true that the GUI Thread should not do long running processes, and that you can't update the user interface in your background Thread - but you never wait for the process to finish before trying to use the response. Either the process is fast and you don't need the Thread, or it is not and you can not rely on it being done when you try to use the response.
A better approach to use the Android AsyncTask. It is better suited to do just this sort of thing.
Finally, I think you have too much code in your OnClickListener, embedding it in the GUI code. You should try to move as much of it as you can out. For example, you have the SimpleHttpClient class - why not make a String loginToServer(String userName, String password) method which does the calls for getting the URL, submitting the post, and waiting for the response, then returns the response. You have that layer so you should use it to abstract out the commands and make them as simple as possible - and you should always strive to keep as much work as possible out of your display code.
For the reference of others, here is the code I am discussing:
Joined: Aug 12, 2011
Thanks for the comment Steve..
I was just thinking of communicating with the server.
The code has been updated with AsyncTask and https support. Please go through the below post. I hope this would be helpful for others.
it looks like you're new to java, so i'd recommend using an external library such as parse for this. they handle all the security parts and it's free for up to 1 million api requests per month. I'm not new to java and I'm using it in my android app because it made getting started that much easier.