zzazzles
zzazzles

Reputation: 167

Is it possible to get a LifecycleOwner from a Worker (or related class)?

I know that Serivces, Activities and Fragments are LifecycleOwners, but I can't seem to find a way to get a LifecycleOwner from a Worker. Is that possible?

Context: I'm migrating some tasks that used to be run by Activities and Services, to be run by Worker as part of the WorkManager framework instead. Some of this code provides a LifecycleOwner via "this", but in a Worker I no longer have those references.

Upvotes: 0

Views: 1641

Answers (1)

zzazzles
zzazzles

Reputation: 167

I think I can use ProcessLifecycleOwner.get(), which works for my purposes. However, since this returns an application-level lifecycle owner vs. an activity- or fragment-specific one, it may not work in other cases.

Upvotes: 1

Related Questions