Can I use SpiceManager inside a service?

I try to connect SpiceManagerto the service, but I get:

java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.octo.android.robospice.SpiceService$SpiceServiceBinder
        at com.octo.android.robospice.SpiceManager$SpiceServiceConnection.onServiceConnected(SpiceManager.java:1072)
        at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java)
        at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java)
        at android.os.Handler.handleCallback(Handler.java)
        at android.os.Handler.dispatchMessage(Handler.java)
        at android.os.Looper.loop(Looper.java)
        at android.app.ActivityThread.main(ActivityThread.java)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
        at dalvik.system.NativeStart.main(Native Method)

the service flow looks something like this:

class MyService extends Service {
    // ...
    SpiceManager mSpiceManager = new SpiceManager(UncachedSpiceService.class);
    // ...

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        mSpiceManager.start(this);
        mSpiceManager.execute(new MyRequest(), new RequestListener<String>() {
            // Handle of request
        })
        // ...
        return START_STICKY;
    }

    // + additional calls to mSpiceManager.execute() in other methods
}

Does this give me this class exception at startup?

+4
source share
2 answers

To use RoboSpice, an entity (context) using SpiceManager and SpiceService must live inside the same process.

RoboSpice acts as a bridge between the Android service and any other context. And this bridge is object-oriented, allowing a bidirectional communication channel based on an object between the context and the service.

Android : SpiceService , SpiceManager, . "" - Android, " ".

, RS . SpiceManager SpiceService, BinderProxy, : Bundles, . RS .

https://github.com/rovo89/XposedBridge/blob/master/src/de/robv/android/xposed/XposedBridge.java, , Zygote . , , fory zygote, , SpiceService, , .

, RoboSpice . - , , , , Android.

+6

/ .

.

public void callService() {
        try {
            org.springframework.web.client.RestTemplate rt = new org.springframework.web.client.RestTemplate();
            rt.getMessageConverters().add(
                    new MappingJacksonHttpMessageConverter());
            String url = "xyz";

            Contacts contacts = rt.postForObject(url, body,
                    Contacts.class);
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "Called-" + e.toString());
        }
    }
-1

All Articles