我正在尝试不断发送请求。我从请求中获取时间变量。我想通过检查从请求中获得的值来一次又一次地发送请求。这是我的要求:
public JSONHandler() {
request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
channelObject = response.getJSONObject("channel0");
song = channelObject.getString("song");
artist = channelObject.getString("artist");
duration = channelObject.getInt("duration");
playedAt = channelObject.getInt("playedat");
channelImg = channelObject.getString("image_extralarge");
// channel0 = new Channel(song, artist, duration, playedAt, channelImg);
channelObject = response.getJSONObject("channel1");
song = channelObject.getString("song");
artist = channelObject.getString("artist");
duration = channelObject.getInt("duration");
playedAt = channelObject.getInt("playedat");
channelImg = channelObject.getString("image_extralarge");
// channel1 = new Channel(song, artist, duration, playedAt, channelImg);
channelObject = response.getJSONObject("channel2");
song = channelObject.getString("song");
artist = channelObject.getString("artist");
duration = channelObject.getInt("duration");
playedAt = channelObject.getInt("playedat");
channelImg = channelObject.getString("image_extralarge");
// channel2 = new Channel(song, artist, duration, playedAt, channelImg);
channelObject = response.getJSONObject("channel3");
song = channelObject.getString("song");
artist = channelObject.getString("artist");
duration = channelObject.getInt("duration");
playedAt = channelObject.getInt("playedat");
channelImg = channelObject.getString("image_extralarge");
// channel3 = new Channel(song, artist, duration, playedAt, channelImg);
channelObject = response.getJSONObject("channel4");
song = channelObject.getString("song");
artist = channelObject.getString("artist");
duration = channelObject.getInt("duration");
playedAt = channelObject.getInt("playedat");
channelImg = channelObject.getString("image_extralarge");
// channel4 = new Channel(song, artist, duration, playedAt, channelImg);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
}
我应该检查“ playedAt” +“持续时间”,之后我想再次发送请求。我像这样在MainActivity中实现此请求:
JSONHandler jsonHandler = new JSONHandler();
检查时间之后,我想再次发送请求,以便更新所需的值。有办法吗?