What I am thinking about authenticating a user on my server is a simple task. I am using AsyncTask as my personal sub-classroom of my activity, but when I try to populate the user object after authentication it keeps it blank. Is it weird that the onPostExecute () method is called? I basically got Asinka Task as my class but ran into the same problem, so I am trying to solve it using a private subclass. Any help? Thank you.
This is my code:
increases public class testing activity {Personal user user; Public user getUser () {this.user return; } Public zero set user (user value) {this.user = value; } Crate on Public Zero (Bundle Saved Instantstate) {Super.Nought (Saved Instantstate); SetContentView (R.layout.main); Last image view icon image = (image view) this.findViewById (R.id.image); Last button test button = (button) this.findViewById (R.id.testButton); Last textview text = (textview) this.findViewById (R.id.text); IconImage.setImageResource (R.drawable.logo_real); TestButton.setOnClickListener (see new OnClickListener) {public void onClick (see v) {Login Task Logan Task = (Login Task) New LoginTask () Execute (New Zero [0]); text.setText (user.getFormattedFullName ());}}); } Private class LoginTask AsyncTask is spreading & lt; Zero, zero, user & gt; {Public Login Task () {} Secure User DoInBackground (Zero ... Parameter) {User newUser = new user (); Try {System.out.println ("Test Work"); HTTP Client Client = New DefaultHttpClient (); HTTPGet Request = New HTTP Gate ("http: //10.0.2.2:8080 / Dogout / Android Lolin +LOGIN_ID=test@gmail.com&password=password = password"); HttpResponse response = client.execute (request); HttpEntity unit = response.getEntity (); InputStream = entity.getContent (); String message = ""; String inputline = ""; Buffettarder BF = New buffed reader (new input recorder); While ((inputLine = bf.readline ()) = null) message + = inputLine; JSONObject returnedUser = new JSONObject (message); Int userId = returnUser.getInt ("userId"); Boolean login = return = returner.batolian ("login_success"); String first name = returning .getString ("firstName"); String last name = returnUser.getString ("lastname"); NewUser.setId (userId); NewUser.setFirstName (firstName); NewUser.setLastName (lastName); NewUser.setLoginSuccess (loginSuccess); Return new user; } Hold (exception e) {newUser.setLoginSuccess (wrong); Return new user; }} Protected void onPostExecute (user user) {setUser (user); }}
should be
protected zero OnPostExecute (User user) {text.setText (user.getFormattedFullName ()); } You created user by AsyncTask (The whole point is that doInBackground (.) runs in a background thread, so UI threads are not blocked.)
Comments
Post a Comment