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

前端 未结 10 924
隐瞒了意图╮
隐瞒了意图╮ 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 03:59

    In my case, the way mentioned above didn't worked for me. Every time I put the bitmap in the intent, the 2nd activity didn't start. The same happened when I passed the bitmap as byte[].

    I followed this link and it worked like a charme and very fast:

    package your.packagename
    
    import android.graphics.Bitmap;
    
    public class CommonResources { 
          public static Bitmap photoFinishBitmap = null;
    }
    

    in my 1st acitiviy:

    Constants.photoFinishBitmap = photoFinishBitmap;
    Intent intent = new Intent(mContext, ImageViewerActivity.class);
    startActivity(intent);
    

    and here is the onCreate() of my 2nd Activity:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bitmap photo = Constants.photoFinishBitmap;
        if (photo != null) {
            mViewHolder.imageViewerImage.setImageDrawable(new BitmapDrawable(getResources(), photo));
        }
    }
    

提交回复
热议问题