简体   繁体   中英

Get Activity Context from Lifecycle object

I have made my component Lifecycle-aware. I want to use activityContext in that component.

My question is: is there any way to use activityContext from the Lifecycle object?

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.

Instead, you should have the code creating your component pass it an Activity context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM