title: How to solve the problem of NDK library calls freezing UI thread
body: <p>I have a C library which I access through NDK. Some operations are time consuming so UI thread freezes on them. As I now the common practice is to use Runnable like that:</p>
  
  <pre><code>myFixedThreadPool.execute(new Runnable() 
  {
    public void run() 
    {
      NativeClass.callToNDKLibrary();
    };
  });
  </code></pre>
  
  <p>or threads like that:</p>
  
  <pre><code>Thread t = new Thread() 
  {
    public void run() 
    {
      NativeClass.callToNDKLibrary();
    }
  };
  t.start();  
  </code></pre>
  
  <p>but the problem is that C library is not thread safe: it starts to crash when I wrap it like this. So the question is how to detach from UI thread still enforcing NDK calls to run one at a time. May be some trick with synchronized will help? I also want to mention that this library is a core underlying layer for my application, not just a helper function. So it's called from nearly every part of my code. And only a few functions consume time, most a quick to keep them in main thread.</p>