java - Login with php return string with AsyncTask in android -
i'm developing android application first time , don't have knoweledge of java,
i've created login screen & integrated parse notification.
now wan't check username & password before sending registration parse api.
i want create asynctask can send http request during onclicklistener,
i want fetch http response, true or false & further function on condition.
e.g. i've inputted username & password , app send request php page, page echo true if username & password correct & false if they're wrong.
and if true next process continue & on false, toast wrong username & password. there quick code make happen?
minor quibble: it's sending request onclicklistener...
you want async tasks ( there no quick code in java, easy stuff long, , elegant stuff abstract =] )
so, in mind: guy great! http://www.vogella.com/tutorials/androidbackgroundprocessing/article.html official( informative ) source http://developer.android.com/reference/android/os/asynctask.html
and here asynctask wrote if want template; obviously, you'd doing basic httprequest instead of using client wrote , not updating spinner &&, when response, return it, do( i'm using class defined matches json coming api ); note can access variables in containing class in doinbackgroud, , access ui in onpostexecute, because of former point, should not in listener, called listener in typical way: new getplaces().execute();
private class getplaces extends asynctask<void, void, places> { @override protected places doinbackground( void[] p1 ) { googleclient client = new googleclient( ); try { return client.executeplacessearchget( urlencoder.encode( editfilter.gettext( ).tostring( ), "utf-8" ), getstring( r.string.places_api_key ), utils.latstringfromlocation( location ) + "," + utils.lngstringfromlocation( location ), 50 ); } catch(unsupportedencodingexception e) {return null;} } @override protected void onpostexecute( places result ) { if( result != null ) { super.onpostexecute( result ); places.clear( ); places.addall( result.results ); placesspinneradapter.notifydatasetchanged( ); placesspinner.setonitemselectedlistener( new adapterview.onitemselectedlistener( ){ public void onitemselected( adapterview<?> adapterview, view view, int position, long id ) { addanchor.this.spinneritemselected( places.get( position ) ); } public void onnothingselected( adapterview<?> p1 ) { } } ); placesspinner.performclick( ); } else log.e( "tag", "empty response!" ); } }
if want put int data, can make constructor , feild in class e.g. new getplaces("username", "password").execute();
and async class have
private class getplaces extends asynctask<void, void, places> { string un; string pwd; public void getplaces(string un, string pwd){ this.un = un; this.pwd = pwd; } @override protected places doinbackground( void[] p1 ) { httprequestblabla.create(un) //or whatever, have code =] } }
gl hf!
Comments
Post a Comment