Home » Where Android apps store data?

Where Android apps store data?

Solutons:


All apps (root or not) have a default data directory, which is /data/data/<package_name>. By default, the apps databases, settings, and all other data go here. This directory is “private” to the app – which means no other app and not even the user can access data in it (without root permissions).

If an app expects huge amounts of data to be stored, or for other reasons wants to “be nice to internal storage”, there’s a corresponding directory on the SDCard (Android/data/<package_name>).

Apart from that, all apps can store data anywhere on the SDCard, as there are no restrictions — and many apps do so. They can use directory names freely (and they again do), which is what often makes it hard to decide what all that “junk” on the card is intended for, and what of it can be deleted.

Though, as Tom pointed out, root-apps could store their data almost everywhere on your device, they usually follow the same rules as other apps.

You can find a general explanation of the Android directory hierarchy in my answer here. For your specific question I might add some more details on the /data/data/<package_name> (and corresponding SD-part):

  • databases/: here go the app’s databases
  • lib/: libraries and helpers for the app
  • files/: other related files
  • shared_prefs/: preferences and settings
  • cache/: well, caches

There might be several more directories in this place, or fewer — it all depends on the app. In its own “home directory” (and that’s what it basically is, spoken Linux-wise) they can place files where they want. Usually, these files and directories are only accessible by the app itself (and root, of course) — other than those stored on the SDCard, which are accessible by all apps.

Some major changes occurred to storage in Android 4.4 (see Android’s Storage Journey). So the following is generally true for Android 4.4+ and particularly 6+.

This is from my detailed answer to How disk space is used on Android device?. Apps’ files are saved (by system and app itself) to internal and external storage under different categories.

DIRECTORY                                                    DESCRIPTION / API
=====================================================================================
APP CODE
========
/data/app/<pkg>*                                             (user apps installation directory)
/data/app/<pkg>*/base.apk                                    (original `.apk` file)
/data/app/<pkg>*/lib/<arch>/*.so                             (shared libraries)
/data/app/<pkg>*/oat/<arch>/base.[art|odex|vdex]             (compiled executable code)
/data/dalvik-cache/<arch>/*.[art|dex|oat|vdex]               (compiled executable code, only for system apps)
/data/misc/profiles/cur/<user_id>/<pkg>/primary.prof         (ART profile)
/data/misc/profiles/ref/<pkg>/primary.prof                   (ART profile)

INTERNAL STORAGE
================
/data/user[_de]/<user_id>/<pkg>                              getDataDir
/data/user[_de]/<user_id>/<pkg>/files                        getFilesDir
/data/user[_de]/<user_id>/<pkg>/[code_]cache                 getCacheDir or getCodeCacheDir
/data/user[_de]/<user_id>/<pkg>/databases                    getDatabasePath
/data/user[_de]/<user_id>/<pkg>/no_backup                    getNoBackupFilesDir
/data/user[_de]/<user_id>/<pkg>/shared_prefs                 getSharedPreferences

EXTERNAL STORAGE
================
/storage/emulated/obb/<pkg>/*.obb                            (shared by multi-users, exposed in following view)
/storage/emulated/<user_id>/Android/obb/<pkg>/*.<pkg>.obb    getObbDirs
/storage/emulated/<user_id>/Android/media/<pkg>              getExternalMediaDirs
/storage/emulated/<user_id>/Android/data/<pkg>/             
/storage/emulated/<user_id>/Android/data/<pkg>/files         getExternalFilesDirs
/storage/emulated/<user_id>/Android/data/<pkg>/[code_]cache  getExternalCacheDirs
  • All of the above paths on internal and external storage (primary and secondary) are app’s private directories which are accessible to respective app without requesting any permission. Apps can also create other directories (not explicitly available through APIs) in their private storage. All of these directories belonging to an app are deleted when the app is uninstalled.

  • Additionally apps can put their data anywhere on primary external storage (including some standard directories and other apps’ private directories) if WRITE_EXTERNAL_STORAGE permission is granted (getExternalStorageDirectory returns /storage/emulated/<user_id>). For secondary external storage and removable storage SAF is used. See details in How to save files to external SD card?.

    However in Android 10 writing directly to primary external shared storage is deprecated (getExternalStorageDirectory and getExternalStoragePublicDirectory are no more available). Apps need to use one of Android’s built-in content providers; either MediaStore (for media files) or SAF (for any other type of files).

  • /data paths may get replaced with /mnt/expand/[UUID] when using Adoptable Storage. /storage/emulated gets replaced with /storage/[UUID] when using secondary external storage (like SD card).

  • For multiple users/profiles <user_id> is different, device owner is always 0. /data/user/0 is a symlink to /data/data for historical reasons. Secondary external storage is only available to device owner.

  • OBB directory is shared among users/profiles (up to Android 9) to save space. FUSE/sdcardfs always exposes /storage/emulated/obb as /storage/emulated/<user_id>/Android/obb.

  • /data/user_de is the Device Encrypted storage on FBE devices which lets certain apps run on boot without asking for user credentials.

  • /data/misc/profiles are used by ART for profile-guided compilation of app code.

  • Description of each directory is somewhat evident from names, details can be seen in API documentation.

  • Caches are cleared by OS when running low on storage, keeping apps exceeding the allotted quota on top.

  • Apps’ private files directories in external storage aren’t automatically scanned by MediaScanner but media directories are.

  • Caches and no_backup directories are not backed up to cloud. See official documentation.

The answer to your question you are asking is too big. I can, however, give you a basic answer which covers the basics.

There are two kinds of apps:
Root and non-root.

Root apps can basically store/modify files wherever they want.

Non-root apps can only store/modify files here: /sdcard/ and every folder what comes after.
Mostly, the installed apps store themselves at /sdcard/Android/data or /sdcard/Android/obb.
Some apps store their save games/configuration data files on /sdcard/APPNAME/, or just on the /sdcard/

To be able to use root apps, you’ll need to have rooted your Android device and have given permission from one of the superuser apps.

Related Solutions

How do I reset a lost administrative password?

By default the first user's account is an administrative account, so if the UI is prompting you for a password it's probably that person's user password. If the user doesn't remember their password you need to reset it. To do this you need to boot into recovery...

How can I use environment variables in Nginx.conf

From the official Nginx docker file: Using environment variables in nginx configuration: Out-of-the-box, Nginx doesn't support using environment variables inside most configuration blocks. But envsubst may be used as a workaround if you need to generate your...

Difference between .bashrc and .bash_profile

Traditionally, when you log into a Unix system, the system would start one program for you. That program is a shell, i.e., a program designed to start other programs. It's a command line shell: you start another program by typing its name. The default shell, a...

Custom query with Castle ActiveRecord

In this case what you want is HqlBasedQuery. Your query will be a projection, so what you'll get back will be an ArrayList of tuples containing the results (the content of each element of the ArrayList will depend on the query, but for more than one value will...

What is the “You have new mail” message in Linux/UNIX?

Where is this mail? It's likely to be in the spool file: /var/mail/$USER or /var/spool/mail/$USER are the most common locations on Linux and BSD. (Other locations are possible – check if $MAIL is set – but by default, the system only informs you about...

How can I find the implementations of Linux kernel system calls?

System calls aren't handled like regular function calls. It takes special code to make the transition from user space to kernel space, basically a bit of inline assembly code injected into your program at the call site. The kernel side code that "catches" the...

Is a composite index also good for queries on the first field?

It certainly is. We discussed that in great detail under this related question: Working of indexes in PostgreSQL Space is allocated in multiples of MAXALIGN, which is typically 8 bytes on a 64-bit OS or (much less common) 4 bytes on a 32-bit OS. If you are not...

Explaining computational complexity theory

Hoooo, doctoral comp flashback. Okay, here goes. We start with the idea of a decision problem, a problem for which an algorithm can always answer "yes" or "no." We also need the idea of two models of computer (Turing machine, really): deterministic and...

Building a multi-level menu for umbraco

First off, no need pass the a parent parameter around. The context will transport this information. Here is the XSL stylesheet that should solve your problem: <!-- update this variable on how deep your menu should be --> <xsl:variable...

How to generate a random string?

My favorite way to do it is by using /dev/urandom together with tr to delete unwanted characters. For instance, to get only digits and letters: tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo '' Alternatively, to include more characters from the OWASP...

How to copy a file from a remote server to a local machine?

The syntax for scp is: If you are on the computer from which you want to send file to a remote computer: scp /file/to/send username@remote:/where/to/put Here the remote can be a FQDN or an IP address. On the other hand if you are on the computer wanting to...

What is the difference between curl and wget?

The main differences are: wget's major strong side compared to curl is its ability to download recursively. wget is command line only. There's no lib or anything, but curl's features are powered by libcurl. curl supports FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP,...

Using ‘sed’ to find and replace [duplicate]

sed is the stream editor, in that you can use | (pipe) to send standard streams (STDIN and STDOUT specifically) through sed and alter them programmatically on the fly, making it a handy tool in the Unix philosophy tradition; but can edit files directly, too,...

How do I loop through only directories in bash?

You can specify a slash at the end to match only directories: for d in */ ; do echo "$d" done If you want to exclude symlinks, use a test to continue the loop if the current entry is a link. You need to remove the trailing slash from the name in order for -L to...

How to clear journalctl

The self maintenance method is to vacuum the logs by size or time. Retain only the past two days: journalctl --vacuum-time=2d Retain only the past 500 MB: journalctl --vacuum-size=500M man journalctl for more information. You don't typically clear the journal...

How can I run a command which will survive terminal close?

One of the following 2 should work: $ nohup redshift & or $ redshift & $ disown See the following for a bit more information on how this works: man nohup help disown Difference between nohup, disown and & (be sure to read the comments too) If your...