1

我有一个运行 RoboSpice 的简单演示。

它是扩展的默认服务,SpringAndroidContentService可以在他们的 github 上找到。

奇怪的是,当我发送请求时,Progress会更新,但我最终没有接到对 的调用onRequestSuccess,这是一个简单的 Toast。

我检查了LogCat,没有例外。以下是相关代码:

/* RestContentRequest overrider */
@Override
public String loadDataFromNetwork() throws Exception {
    RestTemplate restTemplate = getRestTemplate();
    try {
        String response= restTemplate.getForObject(
            "http://xxx.xxx/mobile.html", String.class);
        //does not get called
        Log.d(LOGTAG, response); 
        return response;
    } catch (HttpClientErrorException e) {
        //Does not get called
        Log.e(LOGTAG, e.toString());
        return e.getLocalizedMessage();
    }
}

private class RequestListener implements RequestListener<String>, RequestProgressListener {

    @Override
    public void onRequestFailure(SpiceException exception) {
        //Does not get called
        debug.setText(exception.getLocalizedMessage());
    }

    @Override
    public void onRequestSuccess(String response) {
        //Does not get called
        Toast.makeText( LoginActivity.this, response, Toast.LENGTH_SHORT ).show();
    }

    @Override
    public void onRequestProgressUpdate(RequestProgress progress) {
            //Gets called
            debug.setText(convertProgressToString(progress));
    }

    private String convertProgressToString( RequestProgress progress ) {
        String status = "";
        switch ( progress.getStatus() ) {
            case READING_FROM_CACHE:
                status = "? cache -->";
                break;
            case LOADING_FROM_NETWORK:
                status = "^ network ^";
                break;
            case WRITING_TO_CACHE:
                status = "--> cache";
                break;

            default:
                status = "";
                break;

        }
        return status;
    }

}

这可能是什么原因?它只需要读取一个带有字符串的页面。(纯文本)

4

1 回答 1

0

我不知道您在哪个版本的 RoboSpice 上尝试过,但它绝对可以与 RoboSpice 一起使用。你介意试一试吗?最后一个稳定版本是 1.3.1。

你有一个关于 Stack Over Flow 的 RoboSpice 问题,请通知我或标记它。

于 2012-12-19T23:18:04.300 回答