[英]Get Activity Context from Lifecycle object
I have made my component Lifecycle-aware.我已经让我的组件具有生命周期意识。 I want to use activityContext in that component.
我想在该组件中使用 activityContext 。
My question is: is there any way to use activityContext from the Lifecycle
object?我的问题是:有什么方法可以使用
Lifecycle
object 中的 activityContext 吗?
There is not a way to do this - among other reasons, the LifeCycle
object might not be backed by an Activity
, or even anything attached to an Activity
(for example, ProcessLifecycleOwner
, and components depending on Lifecycle
s should be agnostic of what that lifecycle is.没有办法做到这一点 - 除其他原因外,
LifeCycle
object 可能不受Activity
支持,甚至任何附加到Activity
的东西(例如, ProcessLifecycleOwner
和依赖于Lifecycle
的组件应该不知道该生命周期的内容是。
Instead, you should have the code creating your component pass it an Activity
context.相反,您应该让创建组件的代码将其传递给
Activity
上下文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.