2

I have a retrofit service :

public interface MyService {
    @POST("/dosomething")
    String doSomething(@Part("param") MyType param);
}

and in a dagger module :

@Provides @Singleton
MyService provideService(RestAdapter restAdapter){
    return restAdapter.create(MyMeService.class);
}

//note that restAdapter is also provided by that module.

and in a Tape task i'm using that service, I tried :

    public class MyTask implements Task<MyTask.Callback> {

        //... omitted for brevity 

        @Inject
         MyService mService;

         @Override
         public void execute(final Callback callback) {
            new Thread(new Runnable() {
              @Override
              public void run() {
                 mService.doSomething(new MyType(...));
                 //...
              }
        }
    }

but with this mService is always null. although MyTask is already added in module's @Module( injects = {...}).

So i tried passing context in task's constructor and injecting my task with something like :

MyApplication.get(context).inject(this);

But still got mService always null.

Also when injecting MyService instead in my activity and making it just a field in MyTask and then passing it already created. since MyTask is a Tape task (square's tape library) it fails (understandably) when serializing it with:

Caused by: java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: MyService. Forgot to register a type adapter?

So is there a way to inject retrofit service class correctly in a Tape Task ?

I'm not sure i explained correctly .. i can provide additional information if needed.

Thanks.

Mouna Cheikhna
  • 38,870
  • 10
  • 48
  • 69

0 Answers0