1

RoboSpice を実行するための簡単なデモがあります。

SpringAndroidContentServicegithub にあるように、を拡張するのはデフォルトのサービスです。

奇妙なことに、リクエストを送信するとが更新されますが、最終的に単純なトーストであるProgressへの呼び出しが得られません。onRequestSuccess

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