Source:
private void searchPortal(Portal portal) { mRecyclerView.setAdapter(null); mPortalLoadStateView.setVisibility(View.VISIBLE); mLoadStateTextView.setText("Searching for web map items on the portal at " + portal.getUri()); portal.loadAsync(); portal.addDoneLoadingListener(() -> { if (portal.getLoadStatus() == LoadStatus.LOADED) { try { mLoadStateTextView.setText("Connected to the portal on " + new URI(portal.getUri()).getHost()); } catch (URISyntaxException e) { String error = "Error getting URI from portal: " + e.getMessage(); Log.e(TAG, error); } if (portal.getUser() != null) { mLoadStateTextView.setText("Connected as: " + portal.getUser().getUsername()); } else { mLoadStateTextView.setText("Connected as: Anonymous"); } ListenableFuture<PortalQueryResultSet<PortalItem>> portalItemResult = portal .findItemsAsync(new PortalQueryParameters("type:(\"web map\" NOT \"web mapping application\")")); portalItemResult.addDoneListener(() -> { try { PortalQueryResultSet<PortalItem> portalItemSet = portalItemResult.get(); PortalItemAdapter portalItemAdapter = new PortalItemAdapter(portalItemSet.getResults(), portalItem -> addMap(portal, portalItem.getItemId())); mRecyclerView.setAdapter(portalItemAdapter); mPortalLoadStateView.setVisibility(View.GONE); } catch (ExecutionException | InterruptedException e) { String error = "Error getting portal item set from portal: " + e.getMessage(); Toast.makeText(this, error, Toast.LENGTH_LONG).show(); Log.e(TAG, error); } }); } else { ArcGISRuntimeException loadError = portal.getLoadError(); String error = loadError.getErrorCode() == 17 ? "Portal sign in was cancelled by user." : "Portal sign in failed: " + portal.getLoadError().getCause().getMessage(); Toast.makeText(this, error, Toast.LENGTH_LONG).show(); Log.e(TAG, error); } }); }

Target:
private void searchPortal(Portal portal) { if (portal == null) { Log.e(TAG, "Portal null"); return; } mRecyclerView.setAdapter(null); mPortalLoadStateView.setVisibility(View.VISIBLE); mLoadStateTextView.setText("Searching for web map items on the portal at " + portal.getUri()); portal.loadAsync(); portal.addDoneLoadingListener(() -> { if (portal.getLoadStatus() == LoadStatus.LOADED) { try { mLoadStateTextView.setText("Connected to the portal on " + new URI(portal.getUri()).getHost()); } catch (URISyntaxException e) { String error = "Error getting URI from portal: " + e.getMessage(); Log.e(TAG, error); } if (portal.getUser() != null) { mLoadStateTextView.setText("Connected as: " + portal.getUser().getUsername()); } else { mLoadStateTextView.setText("Connected as: Anonymous"); } ListenableFuture<PortalQueryResultSet<PortalItem>> portalItemResult = portal .findItemsAsync(new PortalQueryParameters("type:(\"web map\" NOT \"web mapping application\")")); portalItemResult.addDoneListener(() -> { try { PortalQueryResultSet<PortalItem> portalItemSet = portalItemResult.get(); PortalItemAdapter portalItemAdapter = new PortalItemAdapter(portalItemSet.getResults(), portalItem -> addMap(portal, portalItem.getItemId())); mRecyclerView.setAdapter(portalItemAdapter); mPortalLoadStateView.setVisibility(View.GONE); } catch (ExecutionException | InterruptedException e) { mPortalLoadStateView.setVisibility(View.GONE); String error = "Error getting portal item set from portal: " + e.getMessage(); Toast.makeText(this, error, Toast.LENGTH_LONG).show(); Log.e(TAG, error); } }); } else { mPortalLoadStateView.setVisibility(View.GONE); ArcGISRuntimeException loadError = portal.getLoadError(); String error = loadError.getErrorCode() == 17 ? "Portal sign in was cancelled by user." : "Portal sign in failed: " + portal.getLoadError().getCause().getMessage(); Toast.makeText(this, error, Toast.LENGTH_LONG).show(); Log.e(TAG, error); } }); }