我有以下代码我想在显示进度对话框时执行(向数据库添加一行):
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://192.168.1.38/hu/Addpost.php?username="+username+"&fname="+firstname+"&lname="+lastname+"&dop="+now+"&content="+post3+"&type="+post_type2+"");
                try
                {
                    nameValuePairs = new ArrayList<NameValuePair>();
                    nameValuePairs.add(new BasicNameValuePair("FirstN",firstname));
                    nameValuePairs.add(new BasicNameValuePair("LastN",lastname));
                    nameValuePairs.add(new BasicNameValuePair("Content",post1));
                    nameValuePairs.add(new BasicNameValuePair("type",post_type));
                    nameValuePairs.add(new BasicNameValuePair("Dateofp",now));
                    nameValuePairs.add(new BasicNameValuePair("username",username));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    response = httpclient.execute(httppost);
                    if(response.getStatusLine().getStatusCode()==200)
                    {
                    entity=response.getEntity();
                    if(entity !=null)
                    {
                        Toast.makeText(getBaseContext(),"POST SUCCESFULLY ADDED",Toast.LENGTH_LONG).show(); 
                    }
                    }
                    else
                    {
                        Toast.makeText(getBaseContext(),"ERROR RERTY OR CHECK YOUR CONNECTION",Toast.LENGTH_LONG).show();
                    }
                    wholepost.setText("");
                }
                catch(Exception ex)
                {Toast.makeText(getBaseContext(),"CONNECTION ERROR",Toast.LENGTH_LONG).show();}
我已经尝试过 AsyncTask 和线程,但没有任何效果,有时它可以工作,但在添加帖子后会显示进度对话框,请问有什么帮助吗?