Stay organized with collections
Save and categorize content based on your preferences.
TokenWatcher
abstract class TokenWatcher
A TokenWatcher watches a collection of IBinder
s. IBinders are added to the collection by calling acquire
, and removed by calling release
. IBinders are also implicitly removed when they become weakly reachable. Each IBinder may be added at most once. The acquired
method is invoked by posting to the specified handler whenever the size of the watched collection becomes nonzero. The released
method is invoked on the specified handler whenever the size of the watched collection becomes zero.
Summary
Public constructors |
Construct the TokenWatcher
|
Public methods |
open Unit |
Record that this token has been acquired.
|
abstract Unit |
Called when the number of active tokens goes from 0 to 1.
|
open Unit |
|
open Unit |
|
open Unit |
|
open Boolean |
|
open Unit |
|
abstract Unit |
Called when the number of active tokens goes from 1 to 0.
|
Public constructors
TokenWatcher
TokenWatcher(
h: Handler!,
tag: String!)
Construct the TokenWatcher
Parameters |
h |
Handler!: A handler to call acquired and released on. If you don't care, just call it like this, although your thread will have to be a Looper thread. new TokenWatcher(new Handler()) |
tag |
String!: A debugging tag for this TokenWatcher |
Public methods
acquire
open fun acquire(
token: IBinder!,
tag: String!
): Unit
Record that this token has been acquired. When acquire is called, and the current count is 0, the acquired method is called on the given handler. Note that the same token
can only be acquired once. If this token
has already been acquired, no action is taken. The first subsequent call to release
will release this token
immediately.
Parameters |
token |
IBinder!: An IBinder object. |
tag |
String!: A string used by the #dump method for debugging, to see who has references. |
acquired
abstract fun acquired(): Unit
Called when the number of active tokens goes from 0 to 1.
dump
open fun dump(): Unit
isAcquired
open fun isAcquired(): Boolean
released
abstract fun released(): Unit
Called when the number of active tokens goes from 1 to 0.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 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 2025-02-10 UTC."],[],[],null,["# TokenWatcher\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nTokenWatcher\n============\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/os/TokenWatcher \"View this page in Java\") \n\n```\nabstract class TokenWatcher\n```\n\n|---|------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.os.TokenWatcher](#) |\n\nA TokenWatcher watches a collection of [IBinder](/reference/kotlin/android/os/IBinder)s. IBinders are added to the collection by calling [acquire](#acquire(android.os.IBinder,%20kotlin.String)), and removed by calling [release](#release(android.os.IBinder)). IBinders are also implicitly removed when they become weakly reachable. Each IBinder may be added at most once. The [acquired](#acquired()) method is invoked by posting to the specified handler whenever the size of the watched collection becomes nonzero. The [released](#released()) method is invoked on the specified handler whenever the size of the watched collection becomes zero.\n\nSummary\n-------\n\n| Public constructors ||\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [TokenWatcher](#TokenWatcher(android.os.Handler,%20kotlin.String))`(`h:` `[Handler](/reference/kotlin/android/os/Handler)!`, `tag:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Construct the TokenWatcher |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [acquire](#acquire(android.os.IBinder,%20kotlin.String))`(`token:` `[IBinder](/reference/kotlin/android/os/IBinder)!`, `tag:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Record that this token has been acquired. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [acquired](#acquired())`()` Called when the number of active tokens goes from 0 to 1. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [cleanup](#cleanup(android.os.IBinder,%20kotlin.Boolean))`(`token:` `[IBinder](/reference/kotlin/android/os/IBinder)!`, `unlink:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` \u003cbr /\u003e |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [dump](#dump())`()` \u003cbr /\u003e |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [dump](#dump(java.io.PrintWriter))`(`pw:` `[PrintWriter](../../java/io/PrintWriter.html#)!`)` \u003cbr /\u003e |\n| open [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [isAcquired](#isAcquired())`()` \u003cbr /\u003e |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [release](#release(android.os.IBinder))`(`token:` `[IBinder](/reference/kotlin/android/os/IBinder)!`)` \u003cbr /\u003e |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [released](#released())`()` Called when the number of active tokens goes from 1 to 0. |\n\nPublic constructors\n-------------------\n\n### TokenWatcher\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nTokenWatcher(\n h: Handler!, \n tag: String!)\n```\n\nConstruct the TokenWatcher\n\n| Parameters ||\n|-------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `h` | [Handler](/reference/kotlin/android/os/Handler)!: A handler to call [acquired](#acquired()) and [released](#released()) on. If you don't care, just call it like this, although your thread will have to be a Looper thread. `new TokenWatcher(new Handler())` |\n| `tag` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: A debugging tag for this TokenWatcher |\n\nPublic methods\n--------------\n\n### acquire\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun acquire(\n token: IBinder!, \n tag: String!\n): Unit\n```\n\nRecord that this token has been acquired. When acquire is called, and the current count is 0, the acquired method is called on the given handler. Note that the same `token` can only be acquired once. If this `token` has already been acquired, no action is taken. The first subsequent call to [release](#release(android.os.IBinder)) will release this `token` immediately.\n\n| Parameters ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `token` | [IBinder](/reference/kotlin/android/os/IBinder)!: An IBinder object. |\n| `tag` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: A string used by the #dump method for debugging, to see who has references. |\n\n### acquired\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun acquired(): Unit\n```\n\nCalled when the number of active tokens goes from 0 to 1. \n\n### cleanup\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun cleanup(\n token: IBinder!, \n unlink: Boolean\n): Unit\n``` \n\n### dump\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun dump(): Unit\n``` \n\n### dump\n\nAdded in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun dump(pw: PrintWriter!): Unit\n``` \n\n### isAcquired\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun isAcquired(): Boolean\n``` \n\n### release\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun release(token: IBinder!): Unit\n``` \n\n### released\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun released(): Unit\n```\n\nCalled when the number of active tokens goes from 1 to 0."]]