code: private void link() {
          synchronized (mDropboxApiLock) {
              if (mDropboxApi != null) {
                  final DropboxAPI<AndroidAuthSession> dropboxApi = mDropboxApi;
  
                  mHandler.post(new Runnable() {
  
                      @Override
                      public void run() {
                          String accountName = null;
                          String shareUrl = null;
                          String accessToken = null;
  
                          // Request params.
                          synchronized (mDropboxApiLock) {
                              // Create directory for storing photos.
                              if (createPhotoFolder(dropboxApi)) {
                                  // Get account params.
                                  accountName = requestAccountName(dropboxApi);
                                  shareUrl = requestShareUrl(dropboxApi);
                                  accessToken = dropboxApi.getSession().getOAuth2AccessToken();
                              }
                          }
  
                          // Validate account settings and store.
                          Handler uiHandler = new Handler(Looper.getMainLooper());
                          if (accountName != null && accountName.length() > 0 && shareUrl != null
                                  && shareUrl.length() > 0 && accessToken != null) {
                              storeAccountParams(accountName, shareUrl, accessToken);
  
                              // Emit link state change event on ui thread.
                              uiHandler.post(new Runnable() {
                                  @Override
                                  public void run() {
                                      notifyLinkStateChanged(new LinkEvent(true));
                                  }
                              });
                          } else {
                              // Handle error on ui thread.
                              uiHandler.post(new Runnable() {
                                  @Override
                                  public void run() {
                                      handleLinkError();
                                  }
                              });
                          }
                      }
                  });
              }
          }
      }
docs: Links an account in a background thread. If unsuccessful, the link error is handled on a ui thread and a
  {@link Toast} will be displayed.