Weak reference and Job: best practices
Hi guys!
It's a simple question for you: must I put all the data passed to my job (into constructor) from some Activities, in WeakReference (not basic type of course!) ?
If yes, how can I use WeakReference correctly, because currently I have an exception "java.lang.RuntimeException: cannot save job to disk" due to WeakReference
Thank you very much
You don’t need to use WeakReferences.... I hope you are not passing your entire Activity in a WeakReference<Activity>...
Just pass in whatever data that you need in order for your Job to complete successfully. If you are using persistent jobs (which it sounds like you are) you need to make sure all job member variables are serializable! So this means you can’t supply your Job with member variables like: Context, List<>(unless the List<> in an instance of ArrayList<>), a custom java object that doesn’t implement serializable, or a custom java object that does implement serializable BUT has fields that do not.
Long Story Short:
Make sure the objects you plan on using in your persistent job implement Serializable otherwise the Job will not be able to be stored to disk and you’ll receive the error that you received.