title: How to synchronously wait the Result callback from Android to Flutter using the invokeMethod?
body: <p>I am trying to synchronously call some Flutter methods from Android (Java) using the Flutter MethodChannel.</p>
  
  <pre><code>    invokeMethod(String method, @Nullable Object arguments, MethodChannel.Result callback)
  </code></pre>
  
  <p>I already tried CountDownLatch, locks and even Threads but would just stop after calling the countdown await or synchronize(lock) or even thread.join. </p>
  
  <pre><code>    public class MainActivity extends AppCompatActivity {
          // code/methods initializations..
  
          public String testData(){
              final String[] result = new String[1];
              final CountDownLatch latch = new CountDownLatch(1);
  
              flutterMethods.invokeMethod("getString", "abcdefg", new MethodChannel.Result() {
                          @Override
                          public void success(Object o) {
                                 result[0] = o.toString();
                                 Log.e(TAG,"success);
                                 latch.countDown(); 
                          }
  
                          @Override
                          public void error(String s, String s1, Object o) {
                                 latch.countDown(); 
                          }
  
                          @Override
                          public void notImplemented() {
                                 latch.countDown(); 
                          }
              }
  
              Log.e(TAG,"about to wait forever!"); 
              latch.await();
              Log.e(TAG,"done!");
              return result[0];
      }
  </code></pre>
  
  <p>Of course, this will work asynchronously without the waits, but I want to make this into a synchronous library function at some point. How can this be done?</p>