How to pass image data from one activity to another activity?

后端 未结 9 684
一生所求
一生所求 2020-11-30 14:26

I am using two activities. One activity displays images in a GridView and by clicking on a particular image in that GridView it should display the

相关标签:
9条回答
  • 2020-11-30 15:14

    In MyGridView: (someInteger is an integer that represents the index of the selected image

    Intent myIntent = new Intent(this, MyImageViewActivity.class);
    Bundle bundle = new Bundle();
    bundle.putInt("image", someInteger);
    myIntent.putExtras(bundle);
    startActivityForResult(myIntent, 0);
    

    In MyImageViewActivity:

    Bundle bundle = this.getIntent().getExtras();
    int pic = bundle.getInt("image");
    

    of course, you can put anything in the bundle! maybe a byte array or something

    0 讨论(0)
  • 2020-11-30 15:20

    Pass the image URL/Uri instead of passing raw image data.

    0 讨论(0)
  • 2020-11-30 15:21

    I suppose you need use Intent class.

    Intent intent = new Intent(YourSourceActivity.this, TargetActivty.class);
    Bundle addinfo = new Bundle();
    
    addinfo.putInt("imageid", someid);
    
    intent.putExtras(addinfo);
    
    0 讨论(0)
提交回复
热议问题