ContainerHolder
Stay organized with collections
Save and categorize content based on your preferences.
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 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 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 Releasable.release()
.
Network activity to check for new versions will stop, and last returned container via getContainer()
will no longer be usable.
Nested Class Summary
interface
Listener object that is called when a new
container is available.
Public Method Summary
abstract Container
|
|
abstract void |
refresh
() Requests a refresh from the network.
|
abstract void |
|
Inherited Method Summary
From interface com.google.android.gms.common.api.Result
From interface
com.google.android.gms.common.api.Releasable
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.
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 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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eContainerHolder\u003c/code\u003e manages and provides access to the active container, which holds tag configurations.\u003c/p\u003e\n"],["\u003cp\u003eWhen a new container version is available, a registered \u003ccode\u003eContainerAvailableListener\u003c/code\u003e is notified.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetContainer()\u003c/code\u003e returns the active container, activating it if necessary and deactivating any previous one.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003erefresh()\u003c/code\u003e triggers a network request to check for and potentially load a newer container version, subject to throttling.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003erelease()\u003c/code\u003e stops container refresh checks and invalidates the last retrieved container, halting tag firing.\u003c/p\u003e\n"]]],[],null,["# ContainerHolder\n\npublic interface **ContainerHolder** implements [Result](/android/reference/com/google/android/gms/common/api/Result) [Releasable](/android/reference/com/google/android/gms/common/api/Releasable) \nHolder for an active container. This container holder holds a container and also manages\nnew versions of the container that may become available (through loading a saved version of\nthe container from disk or from a network refresh).\n\nThis holder can be a successful [Result](/android/reference/com/google/android/gms/common/api/Result), in\nwhich case [getContainer()](/android/reference/com/google/android/gms/tagmanager/ContainerHolder#getContainer())\nreturns a non-null container, and [Result.getStatus()](/android/reference/com/google/android/gms/common/api/Result#getStatus())\nreturns `Status.RESULT_SUCCESS`, or an unsuccessful `Result` in which\ncase `getContainer` returns `null` and `getStatus` returns\nan unsuccessful status.\n\nWhen a new version of a container becomes available, if a [ContainerHolder.ContainerAvailableListener](/android/reference/com/google/android/gms/tagmanager/ContainerHolder.ContainerAvailableListener) has been registered, it will be called.\nAny subsequent call to `getContainer` will make that container active, deactivate\nany previous container, and return the newly-active container. Only active containers fire\ntags; tags in non-active containers never fire.\n\nIf you ever want to stop container refreshing, call [Releasable.release()](/android/reference/com/google/android/gms/common/api/Releasable#release()).\nNetwork activity to check for new versions will stop, and last returned container via\n[getContainer()](/android/reference/com/google/android/gms/tagmanager/ContainerHolder#getContainer())\nwill no longer be usable. \n\n### Nested Class Summary\n\n|-----------|---|---|-------------------------------------------------------------------|\n| interface | [ContainerHolder.ContainerAvailableListener](/android/reference/com/google/android/gms/tagmanager/ContainerHolder.ContainerAvailableListener) || Listener object that is called when a new container is available. |\n\n### Public Method Summary\n\n|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Container](/android/reference/com/google/android/gms/tagmanager/Container) | [getContainer](/android/reference/com/google/android/gms/tagmanager/ContainerHolder#getContainer())() Returns the last loaded container. |\n| abstract void | [refresh](/android/reference/com/google/android/gms/tagmanager/ContainerHolder#refresh())() Requests a refresh from the network. |\n| abstract void | [setContainerAvailableListener](/android/reference/com/google/android/gms/tagmanager/ContainerHolder#setContainerAvailableListener(com.google.android.gms.tagmanager.ContainerHolder.ContainerAvailableListener))([ContainerHolder.ContainerAvailableListener](/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 [refresh()](/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). |\n\n### Inherited Method Summary\n\nFrom interface com.google.android.gms.common.api.Result \n\n|--------------------------------------------------------------------------------|-------------|\n| abstract [Status](/android/reference/com/google/android/gms/common/api/Status) | getStatus() |\n\nFrom interface com.google.android.gms.common.api.Releasable \n\n|---------------|-----------|\n| abstract void | release() |\n\nPublic Methods\n--------------\n\n#### public abstract [Container](/android/reference/com/google/android/gms/tagmanager/Container)\n**getContainer** ()\n\nReturns the last loaded container. If that container is not already active, makes it\nactive, and makes any previously loaded container inactive. \n\n#### public abstract void **refresh** ()\n\nRequests a refresh from the network. This call is asynchronous, so the refresh will\nnot occur immediately.\n\nIn order to limit the frequency of network communication, the refresh method is\nthrottled. After you call `refresh()`, you need to wait at least 15 minutes\nbefore calling this method again, otherwise, the subsequent call will be a no-op. \n\n#### public abstract void **setContainerAvailableListener** ([ContainerHolder.ContainerAvailableListener](/android/reference/com/google/android/gms/tagmanager/ContainerHolder.ContainerAvailableListener) listener)\n\nSets a listener that will be called when a new container becomes available (whether\nin response to an explicit [refresh()](/android/reference/com/google/android/gms/tagmanager/ContainerHolder#refresh())\ncall, via the automatic refreshing that occurs, or as part of the initial loading of\nthe container). That new container won't become active until [getContainer()](/android/reference/com/google/android/gms/tagmanager/ContainerHolder#getContainer()) is called.\n\nIf there is a pending container available when the listener is added, it will be\ncalled immediately.\n\nThe listener will be called on the looper of the handler with which the container\nwas loaded, or the main looper if no such handler was provided. \n\n##### Parameters\n\n| listener | the listener to register (or `null` to unregister) |\n|----------|----------------------------------------------------|"]]