How to pass an imageview that is in an Array List to another imageview in another Activity

Asked

Viewed 117 times

1

Activity 1:

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
    {
        //Pega o item que foi selecionado.
        ItemPromo item = adapterListView.getItem(arg2);
        //Demostração
        //Toast.makeText(this,item.getTexto(), Toast.LENGTH_LONG).show();
        Intent intent = new Intent(this,Promocao.class);
        intent.putExtra("valor1",item.getTexto());
        intent.putExtra("valor2",item.getIconeRid());
        startActivity(intent);
    }

Activity 2:

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_promocao);

        lblTeste = (TextView) findViewById(R.id.lblTeste);
        imgTeste = (ImageView) findViewById(R.id.imgTeste);

        Bundle bundle = getIntent().getExtras();

        if(bundle.containsKey("valor1")){
            String valor = bundle.getString("valor1");
            lblTeste.setText(valor);
        }
        else if(bundle.containsKey("valor2")){
            int v = bundle.getInt("valor2");
            imgTeste.setImageAlpha(v);
        }

    }

1 answer

1

Example:

Bundle extras = new Bundle();
extras.putParcelable("Bitmap", bmp);
intent.putExtras(extras);
startActivity(intent);

And in the second Activity:

Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("Bitmap");
  • If bitmap is a file or resource and you have its ID or file path, it’s always better to pass it than the bitmap itself. What saves a good amount of memory resources and can even prevent problems in the App, since the maximum size of an Intent is around 1mb.

  • You are right, when the application allows the image to be recovered by a URL or the path is worth using this resource and pass a String. As to that of 1MB did not know, thank you for the information.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.