# ContainerHolder

public interface **ContainerHolder** implements [Result](https://developers.google.com/android/reference/com/google/android/gms/common/api/Result) [Releasable](https://developers.google.com/android/reference/com/google/android/gms/common/api/Releasable) 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 `https://developers.google.com/android/reference/com/google/android/gms/common/api/Result`, in
which case `https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder#getContainer()`
returns a non-null container, and `https://developers.google.com/android/reference/com/google/android/gms/common/api/Result#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 `https://developers.google.com/android/reference/com/google/android/gms/tagmanager/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.

If you ever want to stop container refreshing, call `https://developers.google.com/android/reference/com/google/android/gms/common/api/Releasable#release()`.
Network activity to check for new versions will stop, and last returned container via
`https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder#getContainer()`
will no longer be usable.

### Nested Class Summary

|---|---|---|---|
| interface | [ContainerHolder.ContainerAvailableListener](https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder.ContainerAvailableListener) || Listener object that is called when a new container is available. |

### Public Method Summary

|---|---|
| abstract [Container](https://developers.google.com/android/reference/com/google/android/gms/tagmanager/Container) | [getContainer](https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder#getContainer())() Returns the last loaded container. |
| abstract void | [refresh](https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder#refresh())() Requests a refresh from the network. |
| abstract void | [setContainerAvailableListener](https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder#setContainerAvailableListener(com.google.android.gms.tagmanager.ContainerHolder.ContainerAvailableListener))([ContainerHolder.ContainerAvailableListener](https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder.ContainerAvailableListener) listener) Sets a listener that will be called when a new container becomes available (whether in response to an explicit `https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder#refresh()` call, via the automatic refreshing that occurs, or as part of the initial loading of the container). |

### Inherited Method Summary

From interface com.google.android.gms.common.api.Result

|---|---|
| abstract [Status](https://developers.google.com/android/reference/com/google/android/gms/common/api/Status) | getStatus() |

From interface com.google.android.gms.common.api.Releasable

|---|---|
| abstract void | release() |

## Public Methods

#### public abstract [Container](https://developers.google.com/android/reference/com/google/android/gms/tagmanager/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](https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder.ContainerAvailableListener) listener)

Sets a listener that will be called when a new container becomes available (whether
in response to an explicit `https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder#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 `https://developers.google.com/android/reference/com/google/android/gms/tagmanager/ContainerHolder#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 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) |
|---|---|