android-priority-jobqueue icon indicating copy to clipboard operation
android-priority-jobqueue copied to clipboard

Weak reference and Job: best practices

Open anthony3444 opened this issue 8 years ago • 1 comments

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 member variables.

Thank you very much

anthony3444 avatar Aug 01 '17 08:08 anthony3444

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.

JimVanG avatar Nov 15 '17 06:11 JimVanG