ContainerHolder | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Tools & Reference
  - Developer Stories

## Results

Loading...
Summary: Nested Classes | Methods | Inherited Methods | [Expand All]
public interface

# ContainerHolder

implements Releasable Result

com.google.android.gms.tagmanager.ContainerHolder

## Class Overview

Holder for an active container. This container holder holds a container and also manages new versions of the container that may become available (through loading a saved version of the container from disk or from a network refresh).

This holder can be a successful `Result`, in which case `getContainer()` returns a non-null container, and `getStatus()` returns `Status.RESULT_SUCCESS`, or an unsuccessful `Result` in which case `getContainer` returns `null` and `getStatus` returns an unsuccessful status.

When a new version of a container becomes available, if a `ContainerHolder.ContainerAvailableListener` has been registered, it will be called. Any subsequent call to `getContainer` will make that container active, deactivate any previous container, and return the newly-active container. Only active containers fire tags; tags in non-active containers never fire.

Although the `ContainerHolder` will download new versions of the container from the network on a regular basis (approximately every twelve hours), you can make an explicit request to download a new version with `refresh()`.

If you ever want to stop container refreshing, call `release()`. Network activity to check for new versions will stop, and last returned container via `getContainer()` will no longer be usable.

## Summary

Nested Classes
interface | ContainerHolder.ContainerAvailableListener | Listener object that is called when a new container is available.

Public Methods
abstract Container | getContainer() Returns the last loaded container.
abstract void | refresh() Requests a refresh from the network.
abstract void | setContainerAvailableListener(ContainerHolder.ContainerAvailableListener listener) Sets a listener that will be called when a new container becomes available (whether in response to an explicit `refresh()` call, via the automatic refreshing that occurs, or as part of the initial loading of the container).

[Expand] Inherited Methods
From interface com.google.android.gms.common.api.Releasable
abstract void | release()
From interface com.google.android.gms.common.api.Result
abstract Status | getStatus()

## Public Methods

#### public abstract Container getContainer ()

Returns the last loaded container. If that container is not already active, makes it active, and makes any previously loaded container inactive.

#### public abstract void refresh ()

Requests a refresh from the network. This call is asynchronous, so the refresh will not occur immediately.

In order to limit the frequency of network communication, the refresh method is throttled. After you call `refresh()`, you need to wait at least 15 minutes before calling this method again, otherwise, the subsequent call will be a no-op.

#### public abstract void setContainerAvailableListener (ContainerHolder.ContainerAvailableListener listener)

Sets a listener that will be called when a new container becomes available (whether in response to an explicit `refresh()` call, via the automatic refreshing that occurs, or as part of the initial loading of the container). That new container won't become active until `getContainer()` is called.

If there is a pending container available when the listener is added, it will be called immediately.

The listener will be called on the the looper of the handler with which the container was loaded, or the main looper if no such handler was provided.

##### Parameters

listener | the listener to register (or `null` to unregister)