title: Calling pjlib from unknown/external thread. You must " "register external threads with pj_thread_register()
body: <p>I have integrated pjsua2 in my android application. The application crashes when I send an SMS. It doesn't crash every time, it is happening randomly. (once every 10 messages).</p>
  
  <p>MyCode is: </p>
  
  <pre><code>public void sendInstantMessage(String number, String msgBody) {
  
      String buddy_uri = "&lt;sip:" + number + "@" + mPref.getString(PREF_SIPSERVER, "") + "&gt;";
      Log.e(TAG, "sendInstantMessage ==== "+buddy_uri);
  
      BuddyConfig bCfg = new BuddyConfig();
      bCfg.setUri(buddy_uri);
      bCfg.setSubscribe(false);
  
      MyBuddy im = new MyBuddy(bCfg);
      SendInstantMessageParam prm = new SendInstantMessageParam();
      prm.setContent(msgBody);
      prm.setContentType("text/plain; charset=utf-8");
  
      try {
          im.create(account, bCfg);
          boolean valid1 = im.isValid();
          Log.e(TAG, "valid1 ======= "+valid1);
          im.sendInstantMessage(prm);
      } catch (Exception e) {
          Log.e(TAG, "sendInstantMessage ==== "+e);
          e.printStackTrace();
          return;
      }
  
  }
  </code></pre>
  
  <p>According to logcat , I have to call pj_thread_register(). But I have got a method libRegisterThread() in endpoint, so I used it like below</p>
  
  <pre><code>MyApp.ep.libRegisterThread("SipApi");
  </code></pre>
  
  <p>Here is the logcat:</p>
  
  <pre><code>../src/pj/os_core_unix.c:692: pj_thread_this: assertion "!"Calling pjlib from unknown/external thread. You must " "register external threads with pj_thread_register() " "before calling any pjlib functions."" failed
  </code></pre>