Closed bkodirov closed 8 years ago
Who is calling onInject
? Job manager does not have this, did you attach the Injector similar to the dev summit demo does?
https://github.com/yigit/dev-summit-architecture-demo/blob/master/client/app/src/main/java/com/android/example/devsummit/archdemo/di/module/ApplicationModule.java#L109
I'm using Dagger2 by google. onInject is called by super class in the onAdded method.
That wont work because for a persistent job, the instance which receives the onAdded
call is different form the instance that runs. It may even run another time when app is restarted etc.
To properly hook your injector, JobManager provides a dependency injection API: https://github.com/yigit/android-priority-jobqueue/wiki/Job-Manager-Configuration
See the example I linked above.
@yigit You can not inject Base class on Dagger2 unfortunally. You have to go again your injector logic for dagger2. You can not inject like this https://github.com/yigit/dev-summit-architecture-demo/blob/master/client/app/src/main/java/com/android/example/devsummit/archdemo/di/module/ApplicationModule.java#L109 on Dagger2. Because, Dagger2 no longer supports parent injecting.
That example uses dagger2
:). Yes dagger2 made JobManager's API ugly but the way it works in that demo is that it calls the job to call the injector :(. To the injector is not called with the base class.
So the base method in the job has inject
method that receives the app component. Then each job that wants to use the injector override that method to call the injector on themselves. FetchFeedJob
I re-opened the issue. Feel free to close if it is clear or if not, please provide why your use case does not work as in the sample app (which also use Dagger2).
closing due to inactivity + we already have an example of using this with dagger2.
import com.path.android.jobqueue.Params;
import javax.inject.Inject;
import uz.lamuz.player.PlayerApp; import uz.lamuz.player.data.api.service.LikeService; import uz.lamuz.player.jobqueue.BaseJob; import uz.lamuz.player.jobqueue.Groups; import uz.lamuz.player.jobqueue.Priority;
/**
Created by Beka on 1/21/16. */ public class LikeJob extends BaseJob { @Inject LikeService likeService; private String mUserId;
public LikeJob(String userId) { super(new Params(Priority.SYNC).groupBy(Groups.LIKE_SYSTEM).persist()); this.mUserId = userId; }
@Override protected void onInject() { PlayerApp.get().component().inject(this); }
@Override public void onRun() throws Throwable { likeService.like(mUserId, ""); } }
I use Dagger2. Injected field are always null. If remove .persist() it executes without exceptions. I presume it might because of LikeService interface(it is reference by interface). What is the cause of this NPE?