I'm a beginner in android,i save url of image in singleton after i need to send this image to another actitivty in gridview. please someone can help me.
-
1use intent.putextra("KEY","URL"); – Divyesh Patel Mar 07 '17 at 08:10
-
create a model class and pass data using parcelable – Nitesh Mishra Mar 07 '17 at 08:12
-
1Possible duplicate of [Load image from url](http://stackoverflow.com/questions/5776851/load-image-from-url) – MichaelStoddart Mar 07 '17 at 08:33
4 Answers
- The first at all, you need to know how to send data between activities. Refer to: Intent Android
- The next, after you get the url on destinate activity, you need to display it. Refer to: Display image from URL
An example for you: Example

- 1
- 1

- 1,032
- 14
- 38
First send your image url to another Activity
by your Intent
from your current activity
. Like -
Intent intent = new Intent(currentActivity, nextActivity);
input.putExtra("urlKey", "urlValue");
startActivity(intent);
And receive your image url from NextActivity. Like -
Intent intent = getIntent();
String imageUrl = intent.getStringExtra("urlKey");
And use third party library for loading image from web server/ url to view. Take a look on Picasso. Use Picasso
on your Adapter
of GridView
. Ex-
Picasso.with(context)
.load(imageUrl)
.resize(50, 50)
.centerCrop()
.into(yourImageView)

- 2,213
- 3
- 16
- 25
If you use 3rd party library like picasso then you can achieve your goal in few lines of code Do the Following Steps:
- add the following line in the dependency block of your build.gradle file
dependencies { compile 'com.squareup.picasso:picasso:2.5.2' }
- Then load the image into your image view:
Syntax:
Picasso.with(this) .load("YOUR IMAGE URL HERE") .into(imageView);
For example
Picasso.with(this)
.load("https://www.samplecode.co/wp-content/uploads/2015/10/advertise.png")
.into(imageView);
For a gridview , you create an adapter and load the images with the position , refer this adapter class
import android.app.Activity; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.RatingBar; import android.widget.TextView;
import com.drapp.BaseDrawerActivity; import com.drapp.R; import com.squareup.picasso.Picasso;
import java.util.ArrayList;
public class GridViewAdapter extends RecyclerView.Adapter { private Activity activity;
Context context; ArrayList<String> image = new ArrayList<String>(); ArrayList<String> name = new ArrayList<String>(); private static LayoutInflater inflater = null; public GridViewAdapter(BaseDrawerActivity mainActivity, ArrayList<String> thumbnail, ArrayList<String> dish_name) { this.activity = mainActivity; this.context = mainActivity; image = thumbnail; name = dish_name; } public int getCount() { //return textnew1.length; int s = name.size(); return s; } public Object getItem(int position) { return position; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.grid_item_layout, parent, false); // set the view's size, margins, paddings and layout parameters ViewHolder vh = new ViewHolder(v); return vh; } @Override public void onBindViewHolder(ViewHolder holder, int position) { holder.productnametv.setText(name.get(position)); if (image.get(position).equals("")) { holder.productimg.setImageResource(R.drawable.heart); holder.productimg.setVisibility(View.INVISIBLE); } else { Picasso.with(context).load(image.get(position)).into(holder.productimg); } } public long getItemId(int position) { return position; } @Override public int getItemCount() { return name.size(); } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView productnametv; public ImageView productimg; public RatingBar rating; public ViewHolder(View itemView) { super(itemView); productnametv = (TextView) itemView.findViewById(R.id.grid_item_label); productimg = (ImageView) itemView.findViewById(R.id.grid_item_image); } }
}

- 568
- 7
- 28
try this if you dont want to use third party library
new DownloadImage(imamgeview).execute(userProfileUrl);
create a Async Task
public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
CircleImageView bmImage;
public DownloadImage(ImageView bmImage) {
this.bmImage = (CircleImageView) bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.d("Error", e.getStackTrace().toString());
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
i hope you it will work in your case

- 67,701
- 16
- 123
- 163