Hi all,
I have two activities on which I need to show the same image. On the first screen, I download it from a web URL and show it but I don't want to do the same on second screen. I want to save it to Internal Storage when it gets downloaded on the first screen and then simply retrieve it from there to show on second activity. How can I do that?
Here is my code that I am using on first activity:
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
this.SetContentView (Resource.Layout.Main);
String uriString = this.GetUriString();
WebClient web = new WebClient ();
web.DownloadDataCompleted += new DownloadDataCompletedEventHandler(web_DownloadDataCompleted);
web.DownloadDataAsync (new Uri(uriString));
}
void web_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
if (e.Error != null)
{
RunOnUiThread(() =>
Toast.MakeText(this, e.Error.Message, ToastLength.Short).Show());
}
else
{
Bitmap bm = BitmapFactory.DecodeByteArray(e.Result, 0, e.Result.Length);
// THIS IS WHERE I NEED TO SAVE THE IMAGE IN INTERNAL STORAGE //
RunOnUiThread(() =>
{
ProgressBar pb = this.FindViewById<ProgressBar> (Resource.Id.custLogoProgressBar);
pb.Visibility = ViewStates.Gone;
ImageView imgCustLogo = FindViewById<ImageView>(Resource.Id.imgCustLogo);
imgCustLogo.SetImageBitmap(bm);
});
}
}