public void getProfilePic(String username, ImageView imgV) { Bitmap bitmap = null; SoftReference<Bitmap> bitmapSoft = profilePicCache.get(username); if (bitmapSoft == null) { String pathName; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { pathName = context.getExternalFilesDir(null).getAbsolutePath() + "/pgim/" + username; } else pathName = context.getCacheDir().getAbsolutePath() + "/pgim/" + username; if (new File(pathName).exists()) { Log.e(TAG, "Get pic from local"); bitmap = BitmapUtil.getBitmapFromLocal(pathName); profilePicCache.put(username, new SoftReference<Bitmap>(bitmap)); } else { new ProfileImageLoader(imgV, pathName).execute(username); return; } } else { if (bitmapSoft.get() == null) { System.out.println("soft bitmap null"); String pathName; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { pathName = context.getExternalFilesDir(null).getAbsolutePath() + "/pgim/" + username; } else pathName = context.getCacheDir().getAbsolutePath() + "/pgim/" + username; if (new File(pathName).exists()) { Log.e(TAG, "Get pic from local"); bitmap = BitmapUtil.getBitmapFromLocal(pathName); profilePicCache.put(username, new SoftReference<Bitmap>(bitmap)); } else { new ProfileImageLoader(imgV, pathName).execute(username); return; } } else { Log.e(TAG, "Get pic from softreference"); bitmap = bitmapSoft.get(); } } if (bitmap != null) { imgV.setImageBitmap(bitmap); } }