Home > database >  How to pass complex obeject to Worker class?
How to pass complex obeject to Worker class?

Time:01-08

I want to pass my ConnectivityManger to my Worker class. I saw this thread but serialize it to json is not an option for me.

Is there any other way?

My app is designed to use newest api.

CodePudding user response:

You shouldn't pass your ConnectivityManager to your Worker class via input data for a number of reasons:

  1. WorkManager automatically handles connectivity changes when you using NetworkType as part of your work constraints

  2. WorkManager allows injecting dependencies into your Workers via Hilt

  3. If you are referring to Android's ConnectivityManager (and not your own class you've created), then each Worker can already gain access to a Context and, with that, any system service, such as a ConnectivityManager.

  •  Tags:  
  • Related