I am building an Android app in which user are required to choose a nick name. Now, two users cannot have same nick name. I have seen forms on .net where we can verify the availability of a particular username while user types or presses tab using Ajax calls.
My questions is – is anything like that available for Android. Can I query my server on the fly and verify the availability of a nick name.
Thanks a lot for your responses. If there are any tutorials, samples or Android doc references I need to look at please guide me to that.
you could query your server’s database of users with the currently entered username on every keypress event for the specified input component(
EditText, etc), but that might be pretty network intensive and spawn a lot of threads to handle:TextWatcherto your inputEditTextor whatever the user is entering his name intoonTextChangedmethod, you would spawn a thread to contact your database sending along theCharSequencevalue. the response from your server would output some JSON perhaps with a boolean property which says if the username is available or notor…
or…
when you app starts(right before they must pick a name), contact your server’s database and send the app a response holding a list of names that are already taken.
this way, you can easily check if the name is taken locally on the phone rather then sending off a request to check.
you must still always check the availability of the nickname right before saving it on the server side
edit:
I’ve implemented #2, which seems like that’s what the majority of apps do for registering a unique name(that ive seen)
problem with #1
– user enters in 1 letter(network thread started)
– user enteres another letter(another thread started)
– user enters a 3rd letter(another thread)
– thread 2 finishes first, name is valid, user is notified
– thread 1 finishes, name is invalid, user is notified
– thread 3 finishes, name is invalid, user is notified
thread 2 took 4 seconds
thread 1 took 5 seconds
thread 3 took 5 seconds
say user keeps typing for 25 letters, there is a lot you have to keep track of in terms if the name is valid or not, if and what threads are still running, etc
this approach seems a bit too tedious for such a simple registration task, too much hassle
problem with #3
– requires 1 extra network request to the server
i like this approach because you can easily and quickly notify the user if their name is available without any threading(depending how large your user list is) or worrying about how long it will take to check
number 2 is simple, easy, and can have the chance to only require 1 server request