0

I want to have an image sent from recipe_button_list.java to recipe_display_screen.java, and my current code highlights an error in my code...

This is how image is being sent in recipe_button_list:

Intent i= new Intent(getBaseContext(),recipedisplayscreen.class);
            //Sending data to the next screen
            i.putExtra("textView1", inputIngredients1.getText().toString());
            i.putExtra("textView2", inputMethod1.getText().toString());
            i.putExtra("image_string",R.drawable.blustudios);

            Log.e("n", inputMethod1.getText()+"."+ inputIngredients1.getText());

This is how image is recieved in recipe_display_screen:

Intent i = getIntent();
    String Ingredients = i.getStringExtra("textView1");
    String Method = i.getStringExtra("textView2");
    String RecipeImage = i.getStringExtra("image_string");

And this is how it is set (gives error(highlights setImageResource)

        MethodDisplay.setText(Method);
    IngredientsDisplay.setText(Ingredients);
    RecipeDisplay.setImageResource(RecipeImage);

What is my error???

Thanks in advance :P

Bercik
  • 139
  • 1
  • 14

2 Answers2

2

R.drawable.blustudios is not a String. The auto-generated R.java class contains integers which are actually resource ids.

Change this line...

String RecipeImage = i.getStringExtra("image_string");

...to this...

int RecipeImage = i.getIntExtra("image_string", 0);
Squonk
  • 48,735
  • 19
  • 103
  • 135
0

You can't send image as string. You can either use Serialized or Parcable.

I know bitmap is already parcable, maybe ImageView is parcable too check it out. In case it's not, just save the ImageView as a bitmap and send it.

Whatever the case use setParcableExtra() and same with get.

You clearly don't understand the concept of passing data between activites. Check out This question, you will probably figure out the answer from there.

Community
  • 1
  • 1
eric.itzhak
  • 15,752
  • 26
  • 89
  • 142