How can I pass a Bitmap object from one activity to another

前端 未结 10 949
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 03:39

In my activity, I create a Bitmap object and then I need to launch another Activity, How can I pass this Bitmap object from the sub-ac

10条回答
  •  被撕碎了的回忆
    2020-11-22 04:04

    It might be late but can help. On the first fragment or activity do declare a class...for example

       @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            description des = new description();
    
            if (requestCode == PICK_IMAGE_REQUEST && data != null && data.getData() != null) {
                filePath = data.getData();
                try {
                    bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), filePath);
                    imageView.setImageBitmap(bitmap);
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                    constan.photoMap = bitmap;
                } catch (IOException e) {
                    e.printStackTrace();
                }
           }
        }
    
    public static class constan {
        public static Bitmap photoMap = null;
        public static String namePass = null;
    }
    

    Then on the second class/fragment do this..

    Bitmap bm = postFragment.constan.photoMap;
    final String itemName = postFragment.constan.namePass;
    

    Hope it helps.

提交回复
热议问题