androidx.activity
Interfaces
OnBackPressedDispatcherOwner |
A class that has an |
Classes
ComponentActivity |
Base class for activities that enables composition of higher level components. |
OnBackPressedCallback |
Class for handling |
OnBackPressedDispatcher |
Dispatcher that can be used to register |
Extension functions summary
For OnBackPressedDispatcher | |
OnBackPressedCallback |
OnBackPressedDispatcher.addCallback(owner: LifecycleOwner? = null, enabled: Boolean = true, onBackPressed: OnBackPressedCallback.() -> Unit) Create and add a new OnBackPressedCallback that calls onBackPressed in OnBackPressedCallback.handleOnBackPressed. |
For ComponentActivity | |
Lazy<VM> |
ComponentActivity.viewModels(noinline factoryProducer: () -> ViewModelProvider.Factory = null) Returns a Lazy delegate to access the ComponentActivity's ViewModel, if factoryProducer is specified then ViewModelProvider.Factory returned by it will be used to create ViewModel first time. |
Extension functions
addCallback
fun OnBackPressedDispatcher.addCallback(
owner: LifecycleOwner? = null,
enabled: Boolean = true,
onBackPressed: OnBackPressedCallback.() -> Unit
): OnBackPressedCallback
Create and add a new OnBackPressedCallback that calls onBackPressed in OnBackPressedCallback.handleOnBackPressed.
If an owner is specified, the callback will only be added when the Lifecycle is androidx.lifecycle.Lifecycle.State.STARTED.
A default enabled state can be supplied.
viewModels
@MainThread inline fun <reified VM : ViewModel> ComponentActivity.viewModels(noinline factoryProducer: () -> ViewModelProvider.Factory = null): Lazy<VM>
Returns a Lazy delegate to access the ComponentActivity's ViewModel, if factoryProducer is specified then ViewModelProvider.Factory returned by it will be used to create ViewModel first time.
class MyComponentActivity : ComponentActivity() { val viewmodel: MyViewModel by viewmodels() }
This property can be accessed only after the Activity is attached to the Application, and access prior to that will result in IllegalArgumentException.