title: Synchronized doesn't synchronize
body: <p>I have a custom adapter that it's associated with a <code>ListView</code> in my <code>MainActivity</code> class and when I press on one of the items of the List (<code>setOnItemClickListener</code> method) I execute an <code>AsyncTask</code> to retrieve the info from the database and send it into a <code>bundle</code>.</p>
  
  <p>Therefore, I have to wait until the <code>AsyncTask</code> finishes to send the info retrieved in the <code>bundle</code>.</p>
  
  <p>For this purpose, I created an <code>interface</code>:</p>
  
  <pre><code>public interface OnCarListener {
  
      void onCarCompleted(String c);
  
      void onCarError(String error);
  }
  </code></pre>
  
  <p>And I have my <code>AsyncTask</code> in another class:</p>
  
  <pre><code>class findCar extends AsyncTask&lt;Integer, Integer, String&gt; {
  
      private final OnCarListener mListener;
  
      public findCar(OnCarListener listener)
      {
          mListener = listener;
      }
  
      protected void onPreExecute() {
      }
  
      protected String doInBackground(Integer... idCar) {
  
              String nameCar = "";
  
              //Here the code to retrive the info
  
              nameCar = obj.getString("name"); 
  
              //Now nameCar = "Car1"
  
          } catch (Exception ex) {
          }
  
          return nameCar;
      }
  
      protected void onProgressUpdate() {
      }
  
      protected void onPostExecute(String c) {
  
          if (mListener != null) {
              mListener.onCarCompleted(c);
          }
      }
  }
  </code></pre>
  
  <p>And I execute my <code>AsyncTask</code> (in my <code>MainActivity</code>) as follows:</p>
  
  <pre><code>new findCar(new OnCarListener()
  {
      @Override
      public void onCarCompleted(String c) {
  
          synchronized (c) 
          {
              name = c;
          }
      }
  
      @Override
      public void onCarError(String error) {
      }
  }).execute(idCar);
  </code></pre>
  
  <p>And after executing the <code>AsyncTask</code> I throw the bundle:</p>
  
  <pre><code>bundle.putString("name", name);
  </code></pre>
  
  <p><strong>Note:</strong> I send more info with the <code>bundle</code> but I omitted it to simplify the question.</p>
  
  <p>It should work in my opinion but in the first click in one element of the <code>List</code> the <code>name</code> isn't being passed by the <code>bundle</code>, <strong>just in the second and the rest of the clicks</strong> I made at the same or in the rest elements of the <code>List</code>, it works.</p>
  
  <p><strong>Expected result:</strong> <code>AsyncTask</code> will be executed and until it finishes the rest of the code shouldn't work. It is clear that it's not what it's doing right now.</p>
  
  <p><strong>What I want to know:</strong> Why the <code>synchronized</code> doesn't work in the first iteration? I mean, when I have the <code>List</code> and I click on one of the elements of the <code>List</code> the information of the element it's show (in another Activity) but the value <code>name</code> it's not shown.</p>
  
  <p>If I go back and I do one or more clicks on the same element (or a different one) from the <code>List</code>, in all of them appears the value <code>name</code> correctly.</p>
  
  <p>Why in the first iteration it doesn't work?</p>
  
  <p>And I have another question: Why if I quit the <code>synchronized</code> as <code>adelphus</code> said in his answer, any of the times that I click on the elements of the <code>List</code> the value <code>name</code> appears?</p>
  
  <hr>
  
  <p>I tried the solution in this question: <a href="https://stackoverflow.com/questions/11923296/synchronized-not-synchronizing">synchronized not synchronizing</a> but still doesn't work.</p>
  
  <p>What could I do? <em>(Without changing the logic of the program)</em></p>
  
  <p>Thanks in advance!</p>