Data will be displayed at the time of activity creation only.
But what you can do is load the image bitmap in the background and cache it.
And when user opens his sliding menu just set it to the image view instead of loading it again.
Also you can use Universal Image Loader which will load the image only once.
For my profile data you can again fetch all the data from the server while you display loading screen and save this data in SharedPreferences
or in application context and when user moves to my profile just set that data to views.
For loading image bitmap you can use following function call it in asynctask:
public static Bitmap loadBitmap(String url) {
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(new URL(url).openStream(), IO_BUFFER_SIZE);
final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
copy(in, out);
out.flush();
final byte[] data = dataStream.toByteArray();
BitmapFactory.Options options = new BitmapFactory.Options();
//options.inSampleSize = 1;
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);
} catch (IOException e) {
Log.e(TAG, "Could not load Bitmap from: " + url);
} finally {
closeStream(in);
closeStream(out);
}
return bitmap;
}
For reference:
How to load an ImageView by URL in Android?
Or else I found this post you can try it
URL url = new URL(strUrl);
URLConnection connection = url.openConnection();
connection.setUseCaches(true);
Object response = connection.getContent();
if (response instanceof Bitmap) {
Bitmap bitmap = (Bitmap)response;
}
reference:
Android image caching