androidx.core.os

Interfaces

CancellationSignal.OnCancelListener

Listens for cancellation.

ParcelableCompatCreatorCallbacks

This interface is deprecated.

Use android.os.Parcelable.ClassLoaderCreator directly.

Classes

BundleCompat

Helper for accessing features in Bundle.

CancellationSignal

This class is deprecated.

This class was added to the platform in SDK 16, which is below Jetpack's minimum SDK requirement.

ConfigurationCompat

Helper class which allows access to properties of Configuration in a backward compatible fashion.

EnvironmentCompat

Helper for accessing features in Environment.

ExecutorCompat

Helper for accessing features in Executor.

HandlerCompat

Helper for accessing features in Handler.

LocaleListCompat

Helper for accessing features in LocaleList.

MessageCompat

Helper for accessing features in Message.

ParcelCompat

Helper for accessing features in Parcel.

ParcelableCompat

This class is deprecated.

Use android.os.Parcelable.ClassLoaderCreator directly.

ProcessCompat

Helper for accessing features in Process.

TraceCompat

This class is deprecated.

TraceCompat is deprecated in favor of androidx.tracing.Trace.

UserHandleCompat

Helper for accessing features in android.os.UserHandle in a backwards compatible fashion.

UserManagerCompat

Helper for accessing features in android.os.UserManager in a backwards compatible fashion.

Exceptions

OperationCanceledException

An exception type that is thrown when an operation in progress is canceled.

Objects

BuildCompat

This class contains additional platform version checking methods for targeting pre-release versions of Android.

Annotations

BuildCompat.PrereleaseSdkCheck

Experimental feature set for pre-release SDK checks.

Top-level functions summary

Bundle

Returns a new empty Bundle.

Bundle
bundleOf(vararg pairs: Pair<StringAny?>)

Returns a new Bundle with the given key/value pairs as elements.

PersistableBundle

Returns a new empty PersistableBundle.

PersistableBundle
@RequiresApi(value = 21)
persistableBundleOf(vararg pairs: Pair<StringAny?>)

Returns a new PersistableBundle with the given key/value pairs as elements.

inline T
<T : Any?> trace(sectionName: String, block: () -> T)

This function is deprecated. Use androidx.tracing.Trace instead

Extension functions summary

OutcomeReceiver<R, E>
@RequiresApi(value = 31)
<R : Any?, E : Throwable> Continuation<R>.asOutcomeReceiver()

Returns an OutcomeReceiver that will resume this Continuation when an outcome is reported.

inline Runnable
Handler.postAtTime(
    uptimeMillis: Long,
    token: Any?,
    crossinline action: () -> Unit
)

Version of Handler.postAtTime which re-orders the parameters, allowing the action to be placed outside of parentheses.

inline Runnable
Handler.postDelayed(
    delayInMillis: Long,
    token: Any?,
    crossinline action: () -> Unit
)

Version of Handler.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

PersistableBundle

Covert this map to a PersistableBundle with the key/value pairs as elements.

Top-level functions

bundleOf

fun bundleOf(): Bundle

Returns a new empty Bundle.

bundleOf

fun bundleOf(vararg pairs: Pair<StringAny?>): Bundle

Returns a new Bundle with the given key/value pairs as elements.

Throws
kotlin.IllegalArgumentException

When a value is not a supported type of Bundle.

persistableBundleOf

@RequiresApi(value = 21)
fun persistableBundleOf(): PersistableBundle

Returns a new empty PersistableBundle.

persistableBundleOf

@RequiresApi(value = 21)
fun persistableBundleOf(vararg pairs: Pair<StringAny?>): PersistableBundle

Returns a new PersistableBundle with the given key/value pairs as elements.

Supported value types are Int, Long, Double, and String and arrays of these types. On API 22 and later Boolean and BooleanArray are also supported.

Throws
kotlin.IllegalArgumentException

When a value is not a supported type of PersistableBundle.

trace

Added in 1.1.0
Deprecated in 1.5.0
inline fun <T : Any?> trace(sectionName: String, block: () -> T): T

Wrap the specified block in calls to Trace.beginSection (with the supplied sectionName) and Trace.endSection.

Extension functions

asOutcomeReceiver

@RequiresApi(value = 31)
fun <R : Any?, E : Throwable> Continuation<R>.asOutcomeReceiver(): OutcomeReceiver<R, E>

Returns an OutcomeReceiver that will resume this Continuation when an outcome is reported.

Useful for writing suspend bindings to async Android platform methods that accept OutcomeReceiver:

public suspend fun FancinessManager.query(
query: FancinessManager.Query
): FancinessManager.QueryResult = suspendCancellableCoroutine<QueryResult> { continuation ->

// Any Android API that supports cancellation should be configured to propagate
// coroutine cancellation as follows:
val canceller = CancellationSignal()
continuation.invokeOnCancellation { canceller.cancel() }

// Invoke the FancinessManager#queryAsync method as follows:
queryAsync(
query,
canceller,
// Use a direct executor to avoid extra dispatch. Resuming the continuation will
// handle getting to the right thread or pool via the ContinuationInterceptor.
Runnable::run,
continuation.asOutcomeReceiver()
)
}

postAtTime

inline fun Handler.postAtTime(
    uptimeMillis: Long,
    token: Any? = null,
    crossinline action: () -> Unit
): Runnable

Version of Handler.postAtTime which re-orders the parameters, allowing the action to be placed outside of parentheses.

handler.postAtTime(200) {
doSomething()
}
Parameters
token: Any? = null

An optional object with which the posted message will be associated.

Returns
Runnable

the created Runnable

postDelayed

inline fun Handler.postDelayed(
    delayInMillis: Long,
    token: Any? = null,
    crossinline action: () -> Unit
): Runnable

Version of Handler.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

handler.postDelayed(200) {
doSomething()
}
Returns
Runnable

the created Runnable

toPersistableBundle

@RequiresApi(value = 21)
fun Map<StringAny?>.toPersistableBundle(): PersistableBundle

Covert this map to a PersistableBundle with the key/value pairs as elements.

Supported value types are Int, Long, Double, and String and arrays of these types. On API 22 and later Boolean and BooleanArray are also supported.

Throws
kotlin.IllegalArgumentException

When a value is not a supported type of PersistableBundle.