0

I am downloading two different images from Parse SDK.
The two images are downloading properly (I have confirmed it by downloading one type of image only)
After downloading the images, same images are set into the lruCache.
I think there is some problem with my code in Async Tas as shown below:

@Override
    protected String doInBackground(String... params) {
        try {
            ParseQuery<ParseObject> queryTable = ParseQuery.getQuery(TagClass.LOGIN_CREDENTIALS);
            List<ParseObject> objectNames = queryTable.find();
            lruCache = LRUCacheClass.getCache();
            for(ParseObject objectName:objectNames)
            {
                if(objectName.getString(TagClass.USER_ID).equals(params[0]))
                {
                    while(true) {
                        if (bitmapCoverPic == null) {
                            bitmapCoverPic = MyUtilities.decodeParseFileToBitmap(TagClass.COVER_PIC, (ParseFile) objectName.get(TagClass.COVER_PIC));
                        }
                        else
                        {
                            while(true) {
                                if(bitmapProfilePic==null) {
                                    bitmapProfilePic = MyUtilities.decodeParseFileToBitmap(TagClass.PROFILE_PICTURE, (ParseFile) objectName.get(TagClass.PROFILE_PICTURE));
                                }
                                else break;
                            }
                            break;
                        }
                    }
                    lruCache.put(TagClass.PROFILE_PICTURE,bitmapProfilePic);
                    lruCache.put(TagClass.COVER_PIC, bitmapCoverPic);
                }
            }
        }
        catch(ParseException parseException)
        {
            Log.e(TagClass.EXCEPTIONCATCH,"",null);
        }
        return "";
    }

Code in MyUtilties:

public static Bitmap  decodeParseFileToBitmap(String type,ParseFile parseFile) throws ParseException
    {
        parseFile.getDataInBackground(new GetDataCallback() {

            @Override
            public void done(byte[] data, ParseException e) {
                if (e == null) {
                    bitmap = BitmapFactory
                            .decodeByteArray(data, 0, data.length);
                }
            }
        });
        return bitmap;
    }

I am calling Async tasks like below from a Fragment:

AsyncTaskGetLoginDetails asyncTaskGetLoginDetails = new AsyncTaskGetLoginDetails();
            asyncTaskGetLoginDetails.execute(new String[]{userID,loginType});
ojas
  • 247
  • 1
  • 4
  • 17

1 Answers1

0

try replacing

while(true) {
                       if (bitmapCoverPic == null) {
                                bitmapCoverPic = MyUtilities.decodeParseFileToBitmap(TagClass.COVER_PIC, (ParseFile) objectName.get(TagClass.COVER_PIC));
                           }
                            else
                            {
                                while(true) {
                                    if(bitmapProfilePic==null) {
                                        bitmapProfilePic = MyUtilities.decodeParseFileToBitmap(TagClass.PROFILE_PICTURE, (ParseFile) objectName.get(TagClass.PROFILE_PICTURE));
                                        }
                                        else break;
                                    }
                                    break;
                                }
                            }
                            lruCache.put(TagClass.PROFILE_PICTURE,bitmapProfilePic);
                            lruCache.put(TagClass.COVER_PIC, bitmapCoverPic);

with

 bitmapProfilePic = MyUtilities.decodeParseFileToBitmap(TagClass.PROFILE_PICTURE, `(ParseFile) objectName.get(TagClass.PROFILE_PICTURE));`
bitmapCoverPic = MyUtilities.decodeParseFileToBitmap(TagClass.COVER_PIC, (ParseFile) objectName.get(TagClass.COVER_PIC));
if(bitmapProfilePic!=null){
lruCache.put(TagClass.PROFILE_PICTURE,bitmapProfilePic);
                                lruCache.put(TagClass.COVER_PIC, bitmapCoverPic);
  lruCache.put(TagClass.COVER_PIC, bitmapCoverPic);
}
if(bitmapCoverPic!=null{
 lruCache.put(TagClass.PROFILE_PICTURE,bitmapProfilePic);
}
Deepak John
  • 967
  • 1
  • 7
  • 19