Search code examples
androidlistenerofflinerobospice

Robospice RequestListener does not work with offline task


i've got really weird problem. I'm trying to use Robospice for not-networking task (JSON serialization/deserialization).

I've implemented SpiceService (based on offline example from Robospice github) and Requests - doing serialization stuff in loadDataFromNetwork().

I start and stop SpiceManager in OnStart() and OnStop().

My problem is that request is executing but listener is not fired (None of OnRequestSuccess and OnRequestFailure methods are fired)

Here is the line of code responsible for executing task

 manager.execute(saveRequest, new SaveRequestListener());

and my listener

private class SaveRequestListener implements com.octo.android.robospice.request.listener.RequestListener<Boolean> {
    @Override
    public void onRequestFailure(SpiceException spiceException) {
        Log.d("saving",spiceException.getMessage());
        Toast.makeText(getActivity(),"Some error :(((", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRequestSuccess(Boolean aBoolean) {
        Log.d("saving","Saved!!! " + aBoolean);
        Toast.makeText(getActivity(),"Saved!!! " + aBoolean, Toast.LENGTH_SHORT).show();
    }
}

Solution

  • Is there any chance that you are stopping the SpiceManager before expecting the callback?

    In that case, the request will finish as it has already been started, but the RequestListener will never be called since the request listeners are automatically detached. It works this way in order to make sure contexts will not be leaking.