Skip To Content ArcGIS for Developers Sign In Dashboard


You will learn: how to load a layer from an ArcGIS Online item and add it to a map.

The ArcGIS Runtime SDK for Android allows you to access items (such as layers) stored in ArcGIS Online by their item identifier. Using feature layers, you can store geographic features (points, lines, polygons), edit or update attributes, and synchronize changes. As demonstrated in the Display a web map tutorial, you can load and display an existing web map that was pre-configured with a basemap and layers. Alternatively, you can load the individual layers directly from ArcGIS Online and build your map with code. To do so, you need to access each item by ID. You can find an item's ID by browsing to the item on ArcGIS Online and identifying it at the end of the URL, e.g. You can also publish your own feature layer to ArcGIS Online using the Create a new dataset tutorial.

In this tutorial you will learn how to access a layer stored in ArcGIS Online. You will open the layer using its identifier and display its contents on a map.

Before you begin

Make sure you have installed the latest version of Android Studio.

Reuse the starter project

If you have completed the Create a starter app tutorial, then copy the project into a new empty folder. Otherwise, download and unzip the project solution. Open, run, and verify the map displays in the device simulator.


View the Trailheads layer by ID

  1. In your browser, go to the Trailheads Styled layer on ArcGIS Online and find the item ID at the end of the URL. It should be 2e4b3df6ba4b44969a3bc9827de746b3.

Add a new class member

  1. In Android Studio, open the file app > java > {} > Define a new class-level FeatureLayer variable and name it mFeatureLayer to hold a reference to the feature layer that you will create in this tutorial.

    private FeatureLayer mFeatureLayer;
  2. In the setUpMap() method, change the Basemap.Type to TOPOGRAPHIC.

    Basemap.Type basemapType = Basemap.Type.TOPOGRAPHIC;
  3. Add a new method to the class for adding a layer to the map. This method accepts an ArcGISMap as a parameter.

        private void addLayer(final ArcGISMap map) {

Load the portal item

  1. Add to the new method a string variable to hold the item ID of the layer to add.

        String itemID = "2e4b3df6ba4b44969a3bc9827de746b3";
  2. The Portal class provides a way to build applications that work with content from the cloud with ArcGIS Online or on-premises with ArcGIS Enterprise. Create the Portal object for anonymous access using the portal URL. ArcGIS Online's portal URL is

        Portal portal = new Portal("");
  3. Create a variable to store an ArcGIS Online PortalItem. The PortalItem represents content stored in ArcGIS Online - in this case, the Trailheads Styled portal item (feature layer).

        final PortalItem portalItem = new PortalItem(portal, itemID);

Create the layer from the portal item

  1. Create the layer using the portal item and its layer index. The FeatureLayer must be loaded explicitly before it can be used in the map by calling loadAsync() on the feature layer and attaching a listener that is invoked when loading has completed.

        mFeatureLayer = new FeatureLayer(portalItem,0);
        mFeatureLayer.addDoneLoadingListener(new Runnable() {

Add the layer to the map

  1. Ensure the layer is loaded and then add the layer to the map's operational layers.

        mLayer.addDoneLoadingListener(new Runnable() {
            // *** ADD ***
            @Override public void run() {
                if (mFeatureLayer.getLoadStatus() == LoadStatus.LOADED) {
  2. Find the setupMap() method and update it to call the new addLayer() function after the map is added to the map view.

            // *** ADD ***

Add the Trails and Parks and Open Space layers by id

  1. Use the same code pattern in step 5 and 7 to load two more layers into the map. Go to the Trails Styled and the Parks and Open Space Styled layers to find the item IDs and then add the code to add them to the map.

  2. Run your code to view the map. You should see all three layers.

Congratulations, you're done!

Your app should display a map with the trailheads centered on the Santa Monica Mountains. Compare your solution with our completed solution project.


Use your portal item

Instead of using the portal item you used above, use the one you made in the data Create a new dataset tutorial.

In Step 6 above, replace the value of portalItemId with the ID of your portal item.

Find the portal item URL

There are multiple ways to load a feature layer from ArcGIS Online. One way is to load the feature layer directly from a URL. This challenge is a follow-up to the challenge in Create a new dataset design tutorial.

Navigate to the page in ArcGIS Online for your portal item. In the item page, find the Service URL link and identify the service endpoint. This is the URL the runtime uses to access the data. It should look something like this:

Create a ServiceFeatureTable with this URL:

ServiceFeatureTable table =
                new ServiceFeatureTable("");

Create the FeatureLayer from the URL

// Create the layer from the FeatureTable
FeatureLayer layerFromTable = new FeatureLayer(table);

Add the layer to the map


Discover data

If you have not already done so, visit the Discover data tutorial and search for interesting open data you could add in another layer in your app.