Friday 15 February 2013

android - Launch New Activity after correct login -


On my last post I was told that my structure was disturbed so I changed it around so I did not try Doing everything from an activity

My login process takes the details of the login, to see if an ASCN function says that the user is present in my external database: / P>

  increases the public class login activity {@Override protected void onCreate (Bundle saved Instensstet) {Suprknkret (saved Instensstet); SetContentView (R.layout.activity_login); } Public Zero Login (View View) {Edit Text Text; Edit Text Text P; // Get username and password from editing text textUse (= edit text) VVIBiID (RID user name); Text P = (Edit Text) SearchVBIID (RID Password); String Username = TextUtTest (). ToString (); String passW = textP.gettext (). ToString (); Log D. ("Login", user name); Log D. ("Login", password); // log in url string url = "myURL"; String userURLComp = "u =" + userName; String pURLComp = "& amp; p =" + passW; Url = url + userURLComp + pURLComp; Log D. ("Url", url); // async function to get Json's new readLogInJSON (this) .execute (url); }}   

My problem is that if a user is in the database after the async work check I do not know how to start a new activity from async work:

  Public Class ReadLogInJSON AsyncTask and lt; String, zero, string & gt; {Reference C; Public Reedlog Ingestion (reference reference) {c = context; } @ Override protected string doInBackground (string ... arg0) {// TODO auto generated method stub returns Jasonfid (Arg 0 [0]); } Protected Zero PostExecute (string result) {// decode Jason Try Here {JSONObject json = New JSONObject (Results); String position = json.getString ("status"); If (status.equals ("no")) // // toast login failed string message = "login failed"; Toast. Make Text (C, Message, Toast. LNNGHHORAT) Show (); } Else {// Username string user name = json.getString ("userName"); // User ID string UserID = json.getString ("userID"); // Set Priorities Sharing Options Preference = PreferenceManager.getDefaultSharedPreferences (c); SharedPreferences.Editor Editor = preferences.edit (); Editor.putString ("username", user name); Editor.putString ("user id", userID); Editor.commit (); // launch new activity}} hold (exception e) {}} public string readJSonFeed (string url) {stringbilder stringbiller = new stringbilder (); HTTP Client HTTP Client = New DefaultHttpClient (); HttpGet httpGet = New HttpGet (URL); Try {HttpResponse response = httpClient.execute (httpGet); Threaded Positions = Response .getStatusLine (); Int statusCode = statusLine.getStatusCode (); If (statusCode == 200) {HttpEntity entity = response.getEntity (); InputStream inputstream = entity.getContent (); BufferedReader Reader = New BufferedReader (New InputStreamReader (InputStream)); String line; While ((line = reader.readline ()) = faucet {stringBuilder.append (line); } Inputstream.close (); } Else {Log.d ("JSON", "Failed to download file"); }} Hold (exception e) {log d. ("ReadJSONFeed", E..T.O.Localized Message ()); } Return stringBuilder. Toasting (); }}   

Update:

I tried to launch it with:

  c.startActivity (new intent (c , Search.));   

But nothing has been launched.

First of all, you actually want to "LoginAsyncTask" and "SearchActivity" for your class names Should be connected rationally. Second, yes, the proper (and the only) way to start an activity is to call startActivity :) before and after adding a log to startActivity Try, to verify that onPostExecute is actually run.

No comments:

Post a Comment