Search code examples
androidgridviewparse-platformuniversal-image-loader

Android: Obtaining image URL directly from Parse


For fetching url for images from Parse, I have implemented the below codes from Parse.com's examples, as follows:

Code:

@Override
protected Void doInBackground(Void... params) 
{
    // Create the array
    url_photoarraylist = new ArrayList<String>();
    all_info_photoarraylist = new ArrayList<Photos>();
    try 
    {
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("photo_database");
        query.orderByAscending("photo_id");
        ob = query.find();
        for (ParseObject photo_data : ob) 
        {
            ParseFile image = (ParseFile) photo_data.get("photo_file");
            Photos map = new Photos();
            map.set_photo_ref(image.getUrl());
            map.set_user_name((String) photo_data.get("user_name"));
            url_photoarraylist.add(map.get_photo_ref());
            all_info_photoarraylist.add(map);
        }
    } 
    catch (ParseException e) 
    {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }
    return null;
}

Question:

While this works successfully, since I have also used UniversalImageLoader at https://github.com/nostra13/Android-Universal-Image-Loader to load Parse images to GridView, where at there it also re-download the same set of images using URL, I would like to ask whether at the above code, just to obtain the image URL directly instead of getting a ParseFile?

Thanks!


Solution

  • As written here, running a Parse query does not download the contents of the PFFile. This means that running your query to get the PFFiles, and then using UniversalImageLoader with image.getUrl(); won't result in the image downloading twice.