aspose file tools*
The moose likes Android and the fly likes Android Application- Login Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Android Application- Login" Watch "Android Application- Login" New topic
Author

Android Application- Login

D. Capri Michael
Greenhorn

Joined: Jan 16, 2011
Posts: 11
Hi there I'm pretty new to android!
I'm trying to develop an android application which requires login which will link/check with the server/website.
Any suggestion on how can i possibly do it?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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
Greenhorn

Joined: Jan 16, 2011
Posts: 11
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. @@
Prabu Dhanapal
Greenhorn

Joined: Aug 12, 2011
Posts: 21
Hi,

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...

http://androidtechstuffs.blogspot.com/2013/01/login-application-for-android.html
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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:




Steve
Prabu Dhanapal
Greenhorn

Joined: Aug 12, 2011
Posts: 21
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.

http://androidtechstuffs.blogspot.in/2013/01/login-application-for-android-android.html





----------------------------------
Prabu
Jason Mayer
Ranch Hand

Joined: Oct 16, 2007
Posts: 31
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.
http://www.parse.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Android Application- Login