6

I am new to android programming and I have been doing lots of tutorials all over the internet but I keep bumping into deprecated methods, like for example when I call BitmapFactory.Options.inPurgeable, android studio crosses out inPurgeable, giving message that method is deprecated.

Where do I find alternatives to deprecated methods?

Isaac Sekamatte
  • 5,500
  • 1
  • 34
  • 40

2 Answers2

6

It's deprecated because this flag is ignored starting Lollipop. Also use of it can lead to dropped frames. As documentation mentions - use inBitmap method instead.

Maksim Ostrovidov
  • 10,720
  • 8
  • 42
  • 57
0

The documentation says:

This field was deprecated in API level 21. As of Build.VERSION_CODES.LOLLIPOP, this is ignored. In Build.VERSION_CODES.KITKAT and below, if this is set to true, then the resulting bitmap will allocate its pixels such that they can be purged if the system needs to reclaim memory. In that instance, when the pixels need to be accessed again (e.g. the bitmap is drawn, getPixels() is called), they will be automatically re-decoded.

So there should be no need to add this anymore...

... however, according to Romain Guy, it still makes sense when decodeByteArray() is used:

This flag is currently completely ignored' is true in certain cases only - in other cases (e.g. when using decodeByteArray on downloaded data) then this flag is not ignored and is very, very useful

Tobias
  • 7,282
  • 6
  • 63
  • 85
  • Romain Guy answered before change was introduced for Lollipop 21 – Lester Apr 01 '21 at 10:13
  • 4.3.1 contains purgeable related logic https://cs.android.com/android/platform/superproject/+/android-4.3.1_r1:frameworks/base/core/jni/android/graphics/BitmapFactory.cpp 5.1 nothing here https://cs.android.com/android/platform/superproject/+/android-cts-5.1_r20:frameworks/base/core/jni/android/graphics/BitmapFactory.cpp – android_dev Apr 01 '21 at 10:14