java - Returning a value from another class to Activity in Android -


Hi, I am trying to pass the php page from Android form via JSON and try to get results through JSON I am an example and implement it in that example I am entering the username and password in the Android form, on the page through JSN, I send it to the PHP page, the form is retrieving the role of the details passing the database and Android clips The result is going to the problem and my function is setting the value of the text re-filed and the result is displayed in the special text field. Now I want that I want to return the result as a string and get it back into main activity. I am pasting the code below Please help me.

The main activity. Class

  The Public Sector main activity enhances the behavioral activity {Personal edit test user name field, password field, role; Private text view status, method; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); Find UsernameField = (edit )VBIID (RIDAditText1); PasswordField = (edit text) Find VVBIID (RIDAditTet2); Find role = (edit text) VVBIID (RID Edit 3); } Public Zero Login (View View) {String Username = usernameField.getText (). ToString (); String password = passwordField.getText (). ToString (); //method.setText ("Get Method"); New signinactivity (this, role, 0) Execute (username, password); }   

SigninActivity.class

  Public class SigninActivity AsyncTask & lt; String, zero, string & gt; {Private EditText roleField; Personal reference references; GetApost = 0 by private int; Private Static is InputStream; // JSONObject jsonParser; Public SignInactivity (Reference Reference, Edit Text Rollfield, Int Flag) {this.context = context; This .roleField = roleField; this.is = null; // this.jsonParser = new JSONObject (); } @ Override protected string doInBackground (string ... arg0) {// TODO auto generated method stub {string user name = (string) arg0 [0]; String password = (string) arg0 [1]; & Lt; NameValuePair & gt; Parameters = new arreelist & lt; Named Wolopleyre & gt; (); Params.add (New BasicNameValuePair ("name", user name)); Params.add (New BasicNameValuePair ("password", password)); //////////////////////////////////////////////// /////////////////////////// String Link = "http://Myapp.com/login.php"; // URL URL = new URL (link); DefaultHttpClient httpClient = New DefaultHttpClient (); String Paratrating = urlcode utility. Format (Params, "UTF-8"); Link + = "?" + Ultimate String; HttpGet httpGet = new HTTPPhoto (link); HttpResponse httpResponse = httpClient.execute (httpGet); HttpEntity httpEntity = httpResponse.getEntity (); Is = httpEntity.getContent (); Stringbilder sb = new stringbilder () ;; //////////////////////////////////////////////// ///////////////////////// try {BufferedReader Reader = New BufferedReader (New InputStreamRadder ("ISO-8859-1"), 8 ); String line = null; While ((line = reader. Readline ())! = Null () {sb.append (row + "\ n"); } is close(); String jason = sb.toString (); } Hold (exception e) {Log.e ("buffer error", "error in changing result" + e.toString ()); } Return sb.toString (); } Hold (exception e) {return new string ("exception: -" + e.getMessage ()); }} Secure zero (string result) on the peacocksext {this.roleField.setText (result); }   

}

The results here are retrieved and in the PostExecute () function in the SigninActivity class in which I want to myself The text is set to what I want to be returned to main activity in the form of a string, which is to add and break instead of using the text view. I / P>

"post -text "itemprop =" text ">

Its very simple

send in next activity Use it for

  resp = new JSONObject (results); JSONObject Login1Result = resp.getJSONObject ("loginRistalt"); String Stormase = Login result 1 .getString ("EmployeeID"); JSONObject Status = Login1Result.getJSONObject ("status"); If (status.getString ("message"). Ignore equals ("OK")) {intent I = new intent (getApplicationContext (), next.class); I.putExtra ("new_variable_name", strMessage); startActivity (i);   

To get it to the next activity

  {Bundle Extras = Millant (). GetExtras (); String Streemerby IDE = ""; If (additional! = Null) {string value = extras.getString ("new_variable_name"); strEmployeeID = value; } I = new intent (getApplicationContext (), nextTonext.class); I.putExtra ("new_variable_name", strEmployeeID); startActivity (i); }    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -