Get Activity Context from Lifecycle object

675 Views Asked by At

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?

1

There are 1 best solutions below

0
Ryan M On

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 Lifecycles should be agnostic of what that lifecycle is.

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