The ability to store data in a built-in or removable Storage, database, network. Sharedpreference.
Android can use content provider to make your private data leak to other applications.
I. sharedpreference
Two ways to get sharedpreference:
1.getSharedPreferenced (): You can define multiple preference files using this method
2.getPreferenced (): Create only one preference file
Sharedpreference is not strictly used to store "User Configuration". For example, store the user's ringtone. If your application is interested in creating a user configuration, you can use Preferenceactivity,
Two. Built-in storage
Steps to create and write a file:
Use Openfileoutput to get fileoutputstream. Write the data through this stream.
Read data steps from the built-in storage:
Use Openfileinput to get FileInputStream to read the data through this stream.
Suppose you want to save a static file in your application at compile time. Can be saved in the res/raw/path, opened by calling Openrawresource incoming r.raw.<filename>.
Suppose you want to cache data instead of persisting the data, and you can use Opencachedir () to open an internal storage file when you want to cache the data.
When the device has insufficient built-in storage space. Android will delete these files to restore space. However, you do not have to delete these files voluntarily, but you should limit the amount of space that the cache file occupies, rather than 1M.
Other practical methods:
Getfiledir (): Get the absolute path to your built-in file.
Getdir () creates (or opens an existing) path.
DeleteFile () Delete a built-in file
FileList () Returns a list of all the built-in files in the current application
Three. External storage
Let's say you want to write the external store and read the external storage, just ask WRITE_EXTERNAL_STORAGE
for permission.
<manifest ...> <uses-permission Android:name="Android.permission.WRITE_EXTERNAL_STORAGE" android:maxsdkversion=" " /> ...</manifest>
(When the version number is less than 18, use the join permission)
From Android4.4, if you want to use the application's private files, you are not allowed to read and write external storage permissions.
The ability to share this file with other apps by putting the file into music/,pictures/,ringtone/.
If you do not want the system's multimedia browser to be able to browse your multimedia files, you can add. nomedia files to your directory.
The method of getting a public directory getextenrnalStoragepublicdirectory () will participate directory_music/directory_pictures/directory _ringtone incoming.
to Add a brochure under the Public picture directory:
Public FileGetalbumstoragedir(StringAlbumname) { //Get The directory for the user's public pictures directory. Filefile= New File(Environment.getexternalstoragepublicdirectory( Environment.Directory_pictures),Albumname); if (!file.mkdirs()) { Log.e(Log_tag, "Directory not created"); } returnfile;}
You can use Getextenrnalfiledir () to get a private multimedia storage path in the external storage
These files will be deleted when the user deletes your app
These files are not discovered by the system's multimedia browser, butREAD_EXTERNAL_STORAGE权限的应用是可access的。
the buffer of the external storage space is obtained by Getexternalcachedir (). When the application is uninstalled. These files will also be deleted.
need to carefully manage the buffer. Delete caches that are no longer used in your app's life cycle
Four. Using the database
Five. Using the network
How the Android data store is stored