4

I am trying to integrate android-priority-jobqueue in android but onRun is not called i dont know what i am doing wrong.

Here is my Job class

public class UpdateAttachmentJob extends Job {

    long id;
    String token;
    private static final String GROUP = "attachment";
    public static final int PRIORITY = 1;

    public UpdateAttachmentJob(long id,String token) {
        super(new Params(PRIORITY).requireNetwork().persist());
    this.id=id;
    this.token=token;
    }

    @Override
    public void onAdded() {

    }

    @Override
    public void onRun() throws Throwable {

        AttachmentTable tableItem = QueryClass.getData(id);

        new UpdateAttachmentsService().updateAttachment(id, tableItem.Name, tableItem.Description, tableItem.filePath,token ,new ApiCallBack() {

            @Override
            public void onSuccess(Object object) {

                BaseClass baseClass = (BaseClass) object;
                if (baseClass.getStatus() == Constants.status) {
                    QueryClass.deleteSyncTask(id);
                }

            }

            @Override
            public void onError(Object object, String message) {

            }
        });

    }

    @Override
    protected void onCancel() {

    }
}

Here is how i call the job

if (mjobManager==null)
            mjobManager=new JobManager(context);

        mjobManager.addJobInBackground(new UpdateAttachmentJob(id,token));

What am i doing wrong, how to make it work

George Thomas
  • 4,566
  • 5
  • 30
  • 65
  • your job requires network, do you have `ACCESS_NETWORK_STATE` permission? – yigit Feb 23 '16 at 07:42
  • @yigit Yes i have ACCESS_NETWORK_STATE permission – George Thomas Feb 23 '16 at 08:25
  • is mjobManager.start();this mandatory to start – George Thomas Feb 23 '16 at 08:26
  • i have tried configuring job manager before each call, still it doesnot work – George Thomas Feb 23 '16 at 08:30
  • 2
    no it is not mandatory. And NO you should not create a new job manager for each job (or whatever you meant by configuring in each run). Can you attach an app to the issue on github so I can try to reproduce it? – yigit Feb 23 '16 at 23:23
  • oh before that, can you create the job manager with logging enabled (see github WIKI) The logs may tell you what is wrong. – yigit Feb 23 '16 at 23:23
  • `onRun` is never called for me as well. I have `ACCESS_NETWORK_STATE` permission in my manifest, and I've created my `JobManager` as a Singleton so there will only be one instance. – Sakiboy Feb 26 '16 at 22:36
  • @GeorgeThomas, it ended up being a `Serialization` error. Make sure the class that you're trying to persist is Serializable. – Sakiboy Feb 26 '16 at 23:16

0 Answers0