Here is a part of my code: After clicking the button, the connection to the new thread and server has started. If the connection is successful, then the app should start a new activity and end the current. Can anyone explain what is the best way to do this?
transThread.submit (new runnab () {public void run () {guiProgressDialog (true); if (user.length () & lt; 4) GUINotifyUser (" Must be at least 4 characters! "); And if (pass.length () & lt; 4) GUINotifyUser (" The password must have at least 4 characters! ") Else if (! Pass.equals GUINotifyUser (" Your Email Do not have a valid email address! "); Else if (fname.equals (" ") || lname.equals (" ")) guiNotifyUser (" All fields are mandatory! "); {Try {end string message = Autodiscovery Htp on strike signup (user, md5 (pass), mail, fnn, la A); guiNotifyUser (message); // If the message is equal then new activity starts} catch (exception e) {e.printStackTrace ();}} guiProgressDialog (wrong);}} break;; / Code>
You can use it to show how to do it.
I personally want to use asyncTask for this. You can do your work in doInBackground () , then post it to Start on on and activity or You should also UI
AsyncTask Edit the code in the comment I can not say that you are doing without any kind of logic, but the first problem is that when you Start asyncTask in context You do not want to use getApplicationContext () especially the way you are not I think that Paco is getting a NPE because reference has not been started yet, if you are passing context in constructor, you can do this However, it seems that your asyncTask is an internal class register activity / Code> which means that it has access to all the member variables of register activity and its context . This means that you can use context instead of RegisterActivity.This to start your activity . @Override protected void onPostExecute (string result) {super.onPostExecute (results); // if (result == "successful registration!") // string i; // I = "da"; Context.startActivity (new intent (register activity. This, login activity class)); // Change it here As stated, your constructor is not required for context if its internal class but if it was a separate file then This class register is asyncTask and lt; String, zero, string & gt; {Reference reference; Personal RegisterTags (Reference Reference) {this.context = context; Use the variable (reference) given in the constructor above / /
No comments:
Post a Comment