Get image from capture and show image in another layout using another activity in android

前端 未结 4 1242
半阙折子戏
半阙折子戏 2020-12-06 21:23

I want to show image after capture by click button Capture in the FirstActivity and show image in the activity_second(layout) using SecondActivity.

FirstActivity

4条回答
  •  半阙折子戏
    2020-12-06 21:42

    use startActivityForResult() instead of startActivity()

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        Bitmap thumbnail = null;
        if (requestCode == CAMERA_PIC_REQUEST) {
            if (resultCode == RESULT_OK) {
                thumbnail = (Bitmap) data.getExtras().get("data");
                Intent i = new Intent(this, NextActivity.class);
                i.putExtra("name", thumbnail);
                startActivity(i);
            }
        }
    }
    

    Next in the next activity try to use this

    protected void onCreate(Bundle savedInstanceState) {
        //TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        //intialize the image view 
    
        Bitmap bitmap  = getIntent().getExtras().getParcelable("name");
        //set the image here.
    }
    

    Hope this may help you

提交回复
热议问题