Android serializable problem

前端 未结 6 695
眼角桃花
眼角桃花 2021-01-04 19:07

I created a class, which has several member variables, all of which are serializable... except one Bitmap! I tried to extend bitmap and implement serializable, not thinking

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 19:26

    I had the same problem.

    And i decided like this.

    Bitmap is Parcelable, so I made following to my class.

    1. I made Constructor which gets Bundle object , and getter that returns Bundle representing Objects data. So while Bitmap is parcelable , Bundle can save bitmap as parcelable in it.

    2. When you need to pass Date in intent , you can call objects getBundle() method and pass with Intent.putExtra(String key,Bundle value)

    3. In target activity you will call getBundle(String key) and pass it to constructor.

      I think it's very easy approach.

提交回复
热议问题