Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Android 4.2 will try to fetch resource from drawable-xhdpi-v4

Tags:

android

Recently, I get quite a number of crash reports

android.content.res.Resources$NotFoundException: File res/drawable-xhdpi-v4/flag_au.png from drawable resource ID #0x7f0200bc
    at android.content.res.Resources.loadDrawable(Resources.java:1970)
    at android.content.res.Resources.getDrawable(Resources.java:660)

I feel strange that, as the crash reports are from Android 4.2, device @Tab7QC-16

I do have resource in xhdpi. I expect Android 4.2 should pick resources from xhdpi.

I don't plan to provide drawable folder. As, I will place mdpi sized image into it. When the targeted device scales up it to xhdpi, it will not look nice.

I think I can "solve" the crash, by cloning folder xhdpi to xhdpi-v4.

But, the question is, why Android 4 will try to fetch resource from drawable-xhdpi-v4?

like image 934
Cheok Yan Cheng Avatar asked Oct 07 '15 18:10

Cheok Yan Cheng


1 Answers

As I see it, folder resources work the exact opposite way.

The qualifier drawable-v4, for instance, refers to API level 4 and higher, not lower. So if you have these folders:

  • drawable
  • drawable-v4
  • drawable-v15

The drawable-v15 folder will stand for API 15-23 (up to now), drawable-v4 for API 4-14, and drawable for API levels that do not get a match with previous folders (thus API 1-3).

You should probably reformat your folders in this sense.

This is the reference page in the official documentation. For some reason at this moment I can only load it in chinese (I think) but looking at the google cache it seems to support my opinion.

like image 95
natario Avatar answered Oct 27 '22 00:10

natario