I have an object with a BitmapDrawable field that I would like to serialize. I've implemented custom serialization/deserialization with the following methods:
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
art.getBitmap().compress(Bitmap.CompressFormat.WEBP, 100, out);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
art = new BitmapDrawable(BitmapFactory.decodeStream(in));
}
This works, except that the BitmapDrawable constructor without resources is deprecated, and I'd like to use the preferred constructor. What is a good way to get an Android context passed down into readObject?