我是Parse和Android API的新手。我想为我的用户提取图片,但问题是,我们在获取这些图片后无法获取这些图片。确切地说,我使用Loader
,在onCreateLoader
中取回方法后,我无法取回方法onLoadFinished
中的图片。从Android Parse API获取图像时出现问题
我该如何管理?
当前代码:
public Loader<List<ParseUser>> onCreateLoader(int id, Bundle args) {
return new ThrowableLoader<List<ParseUser>>(getActivity(), users) {
// where ThrowableLoader simply extends AsyncLoader which implements loadData
@Override
public List<ParseUser> loadData() throws Exception {
try {
if(getActivity() != null) {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.orderByAscending(Constants.ParseConstants.KEY_USERNAME);
query.setLimit(10);
users = query.find();
bitmap = new Bitmap[users.size()];
for(ParseUser user : users) {
ParseFile file = (ParseFile) user.get("picture");
if(file != null)
file.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
bitmap[0] = BitmapFactory.decodeByteArray(data, 0, data.length); // here I put this bitmap[0] as a test purpose
}
else {
System.out.println("Loading image failed for the user" + e.getMessage());
}
}
});
}
如果userList大小只是1个用户,会得到什么结果?包装“getDatainBackground”的循环“for users”不可能在所有IMO中都很好地扩展。我会查看获取用户照片的url列表,然后花费一些时间优化网络GET和存储为解析文件的照片URL列表上的Bmp.decode。 – 2014-09-11 22:58:07
http://stackoverflow.com/a/13311731/560435 – 2014-09-11 23:00:35
@RobertRowntree对不起,我不明白你的回复。你的意思是我需要使用Loader来查询用户,然后为每个人存储ParseFile对象'ParseFile file =(ParseFile)user.get(“picture”);'。但是,我需要运行'getDataInBackground()',我该在哪里做? – Newben 2014-09-13 21:25:24