Answered in the comments, but the issue is that it's trying to allocate memory for a 599MB bitmap, which is very huge! It's probably a very large image - 4000 x 4000 x 32 bits gets you into the ballpark. It might not be that large in filesize (JPG and PNG can be very efficient) but they unpack into a bitmap, and that memory use depends on the dimensions of the image.
You probably shouldn't be using images that size anyway (or if you are, you might need to look into more efficient ways of displaying them) - but from what it sounds like, you have a list of stuff, and the images should be fairly small. So you definitely don't want to be using huge ones!
Really, you need to work out how large the images should be on the screen (in dp
, same as every other View
is measured in, so it's easy to compare) and then resize them to the appropriate size in pixels. Here's a description of the different densities (with dp to pixel conversions - ideally you'll have a version for each density, resized perfectly and optimised (e.g. you might want to apply sharpening on the smaller ones)
It's not just about optimising the images for display either - constantly scaling large images will make your app run worse, and including resources that are way bigger than you actually need will bloat the APK / App Bundle size. So it's definitely good practice to have images that are exactly what you need!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…