Async Task data being inserted multiple times. Android
<p>I am trying to insert messages by the user to the xml file database.</p>

<p>My client is on android and server on php.Php is responsible for inserting data in xml.</p>

<p>User writes his message in the textbox and press submit the text is inserted in the listview one time but in the database multiple times.</p>

<p>I've tried directly inserting the values in the xml file through <code>php</code> by passing the same arguments which I am sending from the android app and it works fine.It inserts the value only one time. </p>

<p>Here's the code for the submit button which inserts in listview as well as call <code>asynctask</code> to insert in database:</p>

<pre><code>final Button Submit= (Button) findViewById(R.id.SubmitButton);
            Submit.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {

                        String     data=chatbox.getText().toString();

                        HashMap&lt;String,String&gt; hashMap=new HashMap&lt;String,String&gt;();    
                        hashMap.put("You",chatbox.getText().toString());    //insert username(You) value in chatbox to hashmap

                        hashMap.put(HandleJSON.Key_username, "You");
                        hashMap.put(HandleJSON.Key_messageText, data);
                        hashMap.put(HandleJSON.Key_messageDate, UserAdminChatActivity.LastShowingChatDate);

                        HandleJSON.newObject=false;
                        adapter.hashmap.add(adapter.hashmap.size(), hashMap);
                        adapter.notifyDataSetChanged();

                        new InsertAdminChat().execute();

         }});
</code></pre>

<p>Here's the <code>asynctask</code> class which calls the <code>httprequest</code> function to insert data in the database.</p>

<pre><code>     public class InsertAdminChat extends AsyncTask&lt;Void,Void,Void&gt;{

            @Override
            protected Void doInBackground(Void... void1) {
                sendHttpRequest("set", "admin", "You" ,chatbox.getText().toString(),clientEmail,"");                    
                return null;
            }
     }
</code></pre>

<p>This is the httpRequest function:</p>

<pre><code>private String sendHttpRequest(String action,String callFrom,String userName,String chatText,String email,String dateChat)
 {
        httpRequest=new HttpRequest(action,callFrom,userName,chatText,email,dateChat);  
        String data=httpRequest.ExecuteRequest();
        Log.i("mojiiiiii",data);
        httpRequest.ExecuteRequest();
        return data;
 }
</code></pre>

<p>and this is my <code>HTTPREQUEST</code> class which is called by httprequest function and is used to insert the data in the database.</p>

<pre><code>public class HttpRequest {

private final String action;
private final String callFrom;
private final String userName;
private final String chatText;
private final String email;
private final String dateChat;

private HttpClient httpclient;
private HttpGet httpget;
private HttpResponse response ;
private HttpEntity entity;

public HttpRequest(String action,String callFrom,String userName,String chatText,String email,String dateChat)
{


    this.action=action;
    this.callFrom=callFrom;
    this.chatText=chatText;
    this.email=email;
    this.userName=userName; 
    this.dateChat=dateChat;

        httpclient= new DefaultHttpClient();
        httpget = new HttpGet("http://10.116.25.189/php/Chat/xmlManipulator.php?" +
                                                        "action="+this.action+
                                                        "&amp;username="+this.userName+
                                                        "&amp;chatText="+this.chatText+
                                                        "&amp;email="+this.email+
                                                        "&amp;callfrom="+this.callFrom+
                                                        "&amp;dateChatToRetrieve="+URLEncoder.encode(this.dateChat));   //test purposes k liye muazzam
}

public String ExecuteRequest()
{
    try {
    response = httpclient.execute(httpget);
    entity=response.getEntity();

    if(entity!=null)
    {
              InputStream inputStream=entity.getContent();
              String result= convertStreamToString(inputStream);
              Log.i("finalAnswer",result);
              return result;
    }
}
catch (ClientProtocolException e) 
{

    Log.e("errorhai",e.getMessage());
}
catch (IOException e) 
{
    Log.e("errorhai",e.getMessage());
}
    return "";
}

private static String convertStreamToString(InputStream is) {

    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");

        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
 }     



}
</code></pre>
