I am new to Parse and the Android API. I want to fetch pictures of my users, but the problem is that I can't get these pictures after they were fetched. Precisely, I use a Loader
and I can't get back the pictures in the method onLoadFinished
after they were fetched in onCreateLoader
.
How can I manage this?
Current code:
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());
}
}
});
}