title: how to wait for a certain callback method to be called before a function returns in java?
body: <p>I am writing a phonegap plugin.My code outline is this</p>
  
  <pre><code>public PluginResult execute(String action, JSONArray arg1, String arg2) {
        try{
          if (action.equals("authenticate")) {
             this.startlogin();
             return new PluginResult(PluginResult.Status.OK);
          }
          else {
              return new PluginResult(PluginResult.Status.INVALID_ACTION);
          }
         }catch(Exception e){}
              return new PluginResult(PluginResult.Status.JSON_EXCEPTION); 
  
      }
  </code></pre>
  
  <p>startlogin() method calls a function which has callback method registered which gets called after certain event.i.e startlogin() method returns but a certain method is called after an event occurs which is asynchronous.</p>
  
  <pre><code> public void startlogin(){
  
      login();//this has callback method
   }
  </code></pre>
  
  <p>how to wait until that callback method is finished before i return from execute method?
  Whats the best method in java?</p>
  
  <p>PS:I cannot change execute method prototype since phonegap plugin works on execute method.</p>