Pranav P
Pranav P

Reputation: 1815

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?

Upvotes: 1

Views: 795

Answers (1)

Ryan M
Ryan M

Reputation: 20157

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.

Upvotes: 3

Related Questions