0

I am working on an Android app project. It contains a file which contains a JSON. One can use it to mock the API call response during the development of the application.

Should I place that file in the raw folder or in the assets folder in the project?

If you answer, kindly provide reasoning behind it as well.

James Z
  • 12,104
  • 10
  • 27
  • 43
mumayank
  • 1,590
  • 2
  • 18
  • 32
  • I store my JSON file in `assets`. You can check out the difference between them here [https://stackoverflow.com/a/9563467/5444161] – Rahul Agrawal Mar 08 '19 at 11:29
  • 2
    Whichever is appropriate. I'd prefer assets in that case, but it's entirely up to you – Zoe stands with Ukraine Mar 08 '19 at 11:35
  • I'd use `assets` for a group of related things (say help files in different languages) or a font. I'd use `raw` for something unique (a set of sounds, for instance). – Phantômaxx Mar 08 '19 at 12:50
  • I think this question is opinion based. – Gourav Mar 08 '19 at 15:29
  • @Gaurav If preference between 2 things is just opinion based, then it literally means both things are subjectively equal, and hence preferring one over the other is purely subjective. Why would Android keep 2 different distinct folders for doing the exact same thing? Doesn't make sense. – mumayank Mar 08 '19 at 15:38

1 Answers1

1

assets/ is flexible in terms of structure. You can have your own directory tree in there, for organizing lots of files.

res/raw/ is flexible in terms of resource sets. You can have different versions of that resource for different configurations (e.g., res/raw/ as the default, res/raw-zh/ for use on devices configured for Chinese language use).

If you do not need any of those features, assets/ and res/raw/ are about equal in terms of capability. I tend to default to assets/.

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367