Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1019029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:56:50+00:00 2026-05-16T10:56:50+00:00

I figured out how to pass a String value between activites thanks to this

  • 0

I figured out how to pass a String value between activites thanks to this site, however I’m having trouble passing an image. What I’m trying to to is have a user click a button that opens the gallery and allows selecting of a picture. Then I have another button that opens another activity that displays an ImageView. I want to be able to have that ImageView’s image be the chosen one from the previous activity.

Here is the class that has the button I’m clicking to open the gallery and retrieve the chosen image:

public class EnterEdit extends Activity implements View.OnClickListener 
{
private static final int SELECT_IMAGE = 0;

 String filepath;

 Bundle fieldresults;
 Intent b; 

 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.enteredit);

  Button selectwallpaper = (Button) findViewById(R.id.selectwallpaper);
  selectwallpaper.setOnClickListener(this);

  Button previewwallpaper = (Button) findViewById(R.id.previewwallpaper);
  previewwallpaper.setOnClickListener(this);

  fieldresults = new Bundle();
  b = new Intent(this, PreviewScreen.class);
 }


 @Override
 public void onClick(View view) 
 {
  switch (view.getId())
  {
   case R.id.selectwallpaper:
    Intent gallery = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    startActivityForResult(gallery, SELECT_IMAGE);
    break;

   case R.id.previewwallpaper:
     startActivity(b); 
    }
    break;   
  }


 protected void onActivityResult(int requestCode, int resultCode, Intent data)
 {
  super.onActivityResult(requestCode, resultCode, data);

   if (resultCode == RESULT_OK)
   {
    if (requestCode == SELECT_IMAGE)
    {
     Uri selectedimage = data.getData();
     String[] filepathcolumn = {MediaStore.Images.Media.DATA};

     Cursor cursor = getContentResolver().query(selectedimage, filepathcolumn, null, null, null);
     cursor.moveToFirst();

     int columnindex = cursor.getColumnIndex(filepathcolumn[0]);
     filepath = cursor.getString(columnindex);
     cursor.close();

     fieldresults.putString("bitmap", filepath);
     b.putExtras(fieldresults);
    }
   }
 }
}

And here is the class that should display the chosen image:

public class PreviewScreen extends Activity implements View.OnClickListener 
{

 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.previewscreen);

  Bundle fieldresults = this.getIntent().getExtras();
  String backgroundpath = fieldresults.getString("bitmap");

  String background = BitmapFactory.decodeFile(backgroundpath);
  ImageView gallerypic = (ImageView) findViewById(R.id.gallerypic);
  gallerypic.setImageBitmap(background); 
 }
}

What I’m not sure about is in the OnActivityResult if I should pass the selectedImage or the chosenimage in the b.putExtra("bitmap", selectedimage); line. I tried both but I didn’t see an image on the second activity. Also I wasn’t sure in the PreviewScreen class if I’m setting the imageview correctly. Any help is appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:56:51+00:00Added an answer on May 16, 2026 at 10:56 am

    Trust me, you don’t want to be passing images between activities. Rather, why don’t you simply pass the path of the image and let the second activity decide what to do with that path (decode and display the image, in this case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm an encryption novice trying to pass some values back and forth between systems.
EDIT: I figured out the solution. I was not adding -combine to my compile
I am trying to figure out how to use IoC in situations where the
I'm building an ASP.NET MVC site where I want to decorate my ViewModels with
I'm already thinking about to start using simple GET string. Or I'm not so
I am warpping an ArcGIS IFeature object with a class that has my required
I'm currently trying to work through MVC validation, and am coming up against some
I have got a simple flex client requesting some data from a php script.
I want to receive an array that contains all the h1 tag values from
I would like to create a C# WPF form that collects measurements of equipment,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.