Android AsyncTask user experience and error handling-UI components can only be changed in the main thread
You will always use the AsyncTask class frequently, especially in network processing. Check the corrected code first: this is the normal code:
Class sendKeyTask extends AsyncTask
{@ Overrideprotected void onPostExecute (Integer resultCode) {// TODO Auto-generated method stubsuper. onPostExecute (resultCode); switch (resultCode) {case 6000: policyhelper. poppolicyinfo (InnerQuestionActivity. this, "user information exception", ""); break; case 6001: policyhelper. poppolicyinfo (InnerQuestionActivity. this, "Other exceptions", ""); break; case 6002: break; default: break;} // hide the input method InputMethodManager imm = (InputMethodManager) getApplicationContext (). getSystemService (Context. INPUT_METHOD_SERVICE); // display or hide the input method imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS); innerQuestionEdit. setText (""); // refresh new getquestiondetailtack(cmd.exe cute (1) ;}@ Overrideprotected Integer doInBackground (String... data) {// TODO Auto-generated method stubint resultCode = 4001; HttpClient client = new DefaultHttpClient (); HttpPost post = new HttpPost ("http://diandianapp.sinaapp.com/add_key.php "); stringBuilder builder = new StringBuilder (); List
ParamsList = new ArrayList
(); ParamsList. add (new BasicNameValuePair ("access_token", data [0]); paramsList. add (new BasicNameValuePair ("user_name", data [1]); paramsList. add (new BasicNameValuePair ("key_detail", data [2]); paramsList. add (new BasicNameValuePair ("question_id", data [3]); for (int I = 0; I
Some people may say that I asked doInBackground to return a parameter and then process it multiple times in onPostExecute? However, when you combine the two parts, you will find that an error is reported! Generally, the error message is that the UI content can only be changed in the main thread. Why!
Policyhelper. poppolicyinfo (InnerQuestionActivity. this, "Other exceptions", ""); is a pop-up method encapsulation of the dialog box. this is an operation on the UI interface and the problem should be solved here!
Let's look at google's instructions:
Protected abstract Result doInBackground (Params... params) Added in API level 3
Override this method to perform a computation on a background thread. The specified parameters are the parameters passedexecute(Params...)
By the caller of this task. This method can callpublishProgress(Progress...)
To publish updates on the UI thread.
Parameters