Having a problem where it takes too long to load a profile picture from my web server. This is the code I'm using to load the image (in an AsyncTask):
@Override
protected Bitmap doInBackground(Void... params) {
String urlPath = AppVariables.SERVER_ADDRESS + "pictures/" + name + ".JPG";
try {
URLConnection connection = new URL(urlPath).openConnection();
connection.setUseCaches(true);
connection.setConnectTimeout(1000 * 30);
connection.setReadTimeout(1000 * 30);
return BitmapFactory.decodeStream((InputStream) connection.getContent(), null, null);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
This should work according to the top answer here: Android image caching
I still experience a delay though - when I go to 'Profile' in the app it takes a good 2-3 seconds for the profile picture to display.
Any ideas?