0

I am having a Framelayout and some TextViews in my application for which I am loading data from server and setting the background of FrameLayout with Image loaded from server using Picasso and setting TextViews in the same manner. But I want to share it using intent and I am unable to figure out how to do that? Do I have to download the Image First?

My Code in AsyncTask:

 Picasso.with(ctx).load(myPlace.getImg()).into(new Target() {
                        @Override
                        public void onPrepareLoad(Drawable arg0) {
                            // TODO Auto-generated method stub

                        }

                        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                        @Override
                        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom arg1) {
                            // TODO Auto-generated method stub
                            pImg.setBackgroundDrawable(new BitmapDrawable(ctx.getResources(), bitmap));


                        }

                        @Override
                        public void onBitmapFailed(Drawable arg0) {
                            // TODO Auto-generated method stub
                            Toast.makeText(ctx, "Failed Loading", Toast.LENGTH_SHORT).show();
                        }
                    });

                    pname.setText(myPlace.getName());
                    pdes.setText(myPlace.getDescription());

Share Button:

Button shareBtn = (Button) findViewById(R.id.sharebtn);
Mehvish Ali
  • 732
  • 2
  • 10
  • 34

1 Answers1

0

As Picasso will cache the image, you wont need to re download it in another activity(as long as it is on the same application). Add these to your code and see if it helps

steps one and two required only if myPlace is local to AsyncTask

Step 1: make AsyncTask return a MyPlace object

private class ClassName extends AsyncTask<..., ..., MyPlace> {
    ...
}

Step 2: return myPlace object from onPostExecute

Step 3: pack values in bundle and send over intent

Intent intent = new Intent(this, NextActivity.class)
Bundle bundle = new Bundle();
bundle.putString(IMG_URL, myPlace.getImg()); // assuming getImg returns string of url
// put name and desc in the same way
intent.addExtra(bundle);
startActivity(intent);

Step 4: get values in new activity

Intent intent = getIntent();
String url = intent.getExtra().getString(IMG_URL);
// others in the smae way
hello_world
  • 778
  • 1
  • 10
  • 26