> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/android/ja/maps/llms.txt)

# Legacy offline Map

![Use OfflineManager to download tiles.](https://docs.mapbox.com/android/ja/assets/ideal-img/maps-examples-legacy-offline-map.5c966c3.480.png)

This example demonstrates the process of downloading an offline region using the [`OfflineRegionManager`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-offline-region-manager/) and displaying a map at the offline region location using the **Maps SDK for Android**. The app creates an offline region based on specific parameters such as [`geometry`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-offline-region-geometry-definition/geometry.html), [`pixelRatio`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-offline-region-geometry-definition/pixel-ratio.html), [`minZoom`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-offline-region-geometry-definition/min-zoom.html), and [`maxZoom`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-offline-region-geometry-definition/max-zoom.html), and sets the style URL to `Style.STANDARD_SATELLITE`. The callback function [`OfflineRegionCreateCallback`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-offline-region-create-callback/) is used to handle the creation of the offline region, and an [`OfflineRegionObserver`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-offline-region-observer/) monitors the status of the download process, providing feedback on resource download progress and handling any errors that may occur.

Once the offline region download is complete, a button is displayed to load the map at the defined offline region. Clicking the button creates a [`MapView`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-mapbox-map/) with the specified style URI and adjusts the camera position based on the defined zoom level and center point. The map view is then set to be displayed on the screen by calling `setContentView(mapView)`. Additionally, the app manages the lifecycle of the map view by calling [`onStart()`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-mapbox-lifecycle-observer/on-start.html) when the activity starts, [`onStop()`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-mapbox-lifecycle-observer/on-stop.html) when the activity stops, and [`onDestroy()`](https://docs.mapbox.com/android/maps/api/latest/mapbox-maps-android/com.mapbox.maps/-mapbox-lifecycle-observer/on-destroy.html) when the activity is destroyed, ensuring proper resource handling.

> **Note: Android Examples App Available**
> 
> This example code is part of the **Maps SDK for Android Examples App**, a working Android project [available on GitHub](https://github.com/mapbox/mapbox-maps-android/tree/v11.31.0/). Android developers are encouraged to run the examples app locally to interact with this example in an emulator and explore other features of the Maps SDK.
> 
> See our [Run the Maps SDK for Android Examples App](https://docs.mapbox.com/help/tutorials/maps-sdk-android-examples-app/) tutorial for step-by-step instructions.

**Kotlin**

Title: `LegacyOfflineActivity.kt`

[View on GitHub](https://github.com/mapbox/mapbox-maps-android/blob/v11.31.0/app/src/main/java/com/mapbox/maps/testapp/examples/LegacyOfflineActivity.kt)

```kt
package com.mapbox.maps.testapp.examples

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.geojson.Point
import com.mapbox.maps.*
import com.mapbox.maps.testapp.databinding.ActivityLegacyOfflineBinding

/**
 * Example app that downloads an offline region and when succeeded
 * shows a button to load a map at the offline region definition.
 */
@Suppress("DEPRECATION")
class LegacyOfflineActivity : AppCompatActivity() {

  private lateinit var offlineManager: OfflineRegionManager
  private lateinit var offlineRegion: OfflineRegion
  private var mapView: MapView? = null
  private lateinit var binding: ActivityLegacyOfflineBinding

  private val regionObserver: OfflineRegionObserver = object : OfflineRegionObserver {
    override fun errorOccurred(error: OfflineRegionError) {
      if (error.isFatal) {
        logE(TAG, "Fatal error: ${error.type}, ${error.message}")
      } else {
        logW(TAG, "Error downloading some resources:  ${error.type}, ${error.message}")
      }
      offlineRegion.setOfflineRegionDownloadState(OfflineRegionDownloadState.INACTIVE)
    }

    override fun statusChanged(status: OfflineRegionStatus) {
      logD(
        TAG,
        "${status.completedResourceCount}/${status.requiredResourceCount} resources; ${status.completedResourceSize} bytes downloaded."
      )
      if (status.downloadState == OfflineRegionDownloadState.INACTIVE) {
        downloadComplete()
        return
      }
    }
  }

  private val callback: OfflineRegionCreateCallback = OfflineRegionCreateCallback { expected ->
    if (expected.isValue) {
      expected.value?.let {
        offlineRegion = it
        it.setOfflineRegionObserver(regionObserver)
        it.setOfflineRegionDownloadState(OfflineRegionDownloadState.ACTIVE)
      }
    } else {
      logE(TAG, expected.error!!)
    }
  }

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityLegacyOfflineBinding.inflate(layoutInflater)
    setContentView(binding.root)
    offlineManager = OfflineRegionManager()
    offlineManager.createOfflineRegion(
      OfflineRegionGeometryDefinition.Builder()
        .geometry(point)
        .pixelRatio(2f)
        .minZoom(zoom - 2)
        .maxZoom(zoom + 2)
        .styleURL(styleUrl)
        .glyphsRasterizationMode(GlyphsRasterizationMode.NO_GLYPHS_RASTERIZED_LOCALLY)
        .build(),
      callback
    )
  }

  private fun downloadComplete() {
    binding.downloadProgress.visibility = View.GONE
    binding.showMapButton.visibility = View.VISIBLE
    binding.showMapButton.setOnClickListener {
      it.visibility = View.GONE
      // create mapView
      mapView = MapView(
        this@LegacyOfflineActivity,
        MapInitOptions(context = this@LegacyOfflineActivity, styleUri = styleUrl)
      )
      mapView?.mapboxMap?.setCamera(CameraOptions.Builder().zoom(zoom).center(point).build())
      setContentView(mapView)

      mapView?.onStart()
    }
  }

  override fun onStart() {
    super.onStart()
    mapView?.onStart()
  }

  override fun onStop() {
    super.onStop()
    mapView?.onStop()
  }

  override fun onDestroy() {
    super.onDestroy()
    offlineRegion.invalidate { }
    mapView?.onDestroy()
  }

  companion object {
    private const val TAG = "Offline"
    private const val zoom = 16.0
    private val point: Point = Point.fromLngLat(57.818901, 20.071357)
    private const val styleUrl = Style.STANDARD_SATELLITE
  }
}
```