java - Make a Login Activity in Android using my own API -



java - Make a Login Activity in Android using my own API -

i've done api , want utilize android. first of want create login , access mainactivity don't know how utilize api check if info introduced in android login right compared 1 i've stored. how can access info i've stored in database through api?

for example, i've method called getuser in api returns user , it's running in local tomcat. i'd access method android through server , user , compare 1 introduced in android login.

for i've next in login activity:

public class loginactivity extends activity { private final static string tag = loginactivity.class.getname(); private button btnlogin; private edittext inputusername; private edittext inputpassword; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.login_layout); inputusername = (edittext) findviewbyid(r.id.etusername); inputpassword = (edittext) findviewbyid(r.id.etpassword); btnlogin = (button) findviewbyid(r.id.blogin); btnlogin.setonclicklistener( new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub sharedpreferences prefs = getsharedpreferences("mini-profile", context.mode_private); string username = prefs.getstring("username", null); string password = prefs.getstring("password", null); if ((username != null) && (password != null)) { intent intent = new intent(loginactivity.this, minimainactivity.class); startactivity(intent); finish(); } } }); } }

can explain me more or less how it? or know interesting site explained this?

thank you.

you have write asynctask (http://developer.android.com/reference/android/os/asynctask.html) every time want to access api, asyntask has called within onclick, (as asynctask async) wait response in onpostexecute method, , within onpostexecute compare result of api phone call decide whether phone call startactivity(intent); or showing error message (for example). may want show progress in onpreexecute().

you may find many examples of asyntask in google.

java android api login

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -