How to pass bitmap from one activity to another

后端 未结 4 1661
再見小時候
再見小時候 2020-12-04 02:11

i have bitmap in ActivityA i want to pass the bitmap from here to ActivityB, i googled for this. when i use this

Intent intent = new Intent(this, NewActivit         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 02:43

    I tried and its working as below using intent.putExtra("name", bitmap)

    While passing with intent,

    Intent intent = new Intent(Current.this, Next.class);
    intent.putExtra("bmp", bitmap);
    startActivity(intent);
    

    While fetching,

    Bitmap bitmap = getIntent().getParcelableExtra("bmp");
    

    OR

    Other option is to use Application class,

    You can also use a class that extends Application and have a setter getter for Bitmap and call it from every Acitivity.

    ((myApplication_class_name)getApplication()).setBitmap(bmp);
    

    and fetch the Bitmap using,

    ((myApplication_class_name)getApplication()).getBitmap();
    

提交回复
热议问题