是使用
未来目标
您可以在后台加载图像。
启动意图服务并在中加载图像
onHandleIntent
方法。就像,
String data = intent.getStringExtra("data");
try {
JSONObject jsonObject = new JSONObject(data);
JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("res");
for (int i = 0; i < jsonArray.length(); i++) {
if (common.getNetworkType().equalsIgnoreCase("-")) {
stopSelf();
break;
} else {
JSONObject jObj = jsonArray.getJSONObject(i);
FutureTarget<File> future = Glide.with(this).load(common.completeURL(jObj.getString("AvatarImage"))).downloadOnly(400, 400);
try {
future.get();
break;
} catch (InterruptedException e) {
stopSelf();
break;
} catch (ExecutionException e) {
stopSelf();
break;
}
}
}
} catch (Exception e) {
stopSelf();
logger.w(TAG, "onHandleIntent: ", e);
}