how to send image from one activity to other?

為{幸葍}努か 提交于 2019-12-04 07:51:22
madlymad

Solution 1: (for non drawable resources)

You can send the path filename as a string. Just like the "title" in your example.

If you have problem with usage of filepath to ImageView. Show Image View from file path?


Solution 2: (for drawable easy & light way)

Send the resource integer value like:

MAIN ACTIVITY

Intent intent = new Intent(this, SecondActivity.class); 
intent.putExtra("resourseInt", R.drawable.image);    
startActivity(intent); 

SECOND ACTIVITY

@Override 
public void onCreate(Bundle bundle) 
{ 

    super.onCreate(bundle); 
    setContentView(R.layout.pantalla); 
    Bundle extras = getIntent().getExtras(); 
    if (extras == null) 
    { 
        return; 
    } 
    int res = extras.getInt("resourseInt"); 

    ImageView view = (ImageView) findViewById(R.id.something); 

    view.setImageResourse(res); 
}

Put the path of the picture in putExtra. Do not send bitmap it may be heavy

Save filepath

intent.putExtra("imagePath", filepath); 

to send the image through intent and use

String image_path = getIntent().getStringExtra("imagePath");
Bitmap bitmap = BitmapFactory.decodeFile(image_path);
myimageview.setImageDrawable(bitmap);

Drawables are available throughout all the activities in your application .
You can access them directly instead of sending them from one activity to another.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!