data-storage.jd revision 50e990c64fa23ce94efa76b9e72df7f8ec3cee6a
150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainpage.title=Storage Options
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project@jd:body
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<div id="qv-wrapper">
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<div id="qv">
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <h2>Storage quickview</h2>
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <ul>
10779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <li>Use Shared Preferences for primitive data</li>
11779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <li>Use internal device storage for private data</li>
12779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <li>Use external storage for large data sets that are not private</li>
13779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <li>Use SQLite databases for structured storage</li>
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  </ul>
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <h2>In this document</h2>
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <ol>
18779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <li><a href="#pref">Using Shared Preferences</a></li>
1950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main    <li><a href="#filesInternal">Using the Internal Storage</a></li>
2050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main    <li><a href="#filesExternal">Using the External Storage</a></li>
2150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main    <li><a href="#db">Using Databases</a></li>
22779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <li><a href="#netw">Using a Network Connection</a></li>
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  </ol>
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <h2>See also</h2>
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <ol>
279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    <li><a href="#pref">Content Providers and Content Resolvers</a></li>
289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  </ol>
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</div>
319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</div>
329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
33779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Android provides several options for you to save persistent application data. The solution you
34779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainchoose depends on your specific needs, such as whether the data should be private to your
35779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainapplication or accessible to other applications (and the user) and how much space your data
36779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainrequires.
379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</p>
389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
39779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Your data storage options are the following:</p>
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
41779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<dl>
42779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <dt><a href="#pref">Shared Preferences</a></dt>
43779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <dd>Store private primitive data in key-value pairs.</dd>
44779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <dt><a href="#filesInternal">Internal Storage</a></dt>
45779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <dd>Store private data on the device memory.</dd>
46779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <dt><a href="#filesExternal">External Storage</a></dt>
47779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <dd>Store public data on the shared external storage.</dd>
48779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <dt><a href="#db">SQLite Databases</a></dt>
49779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <dd>Store structured data in a private database.</dd>
50779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <dt><a href="#netw">Network Connection</a></dt>
51779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <dd>Store data on the web with your own network server.</dd>
52779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</dl>
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
54779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Android provides a way for you to expose even your private data to other applications
55779de5c040ab53e0dba9f7a21a236209a376f548Scott Main&mdash; with a <a href="{@docRoot}guide/topics/providers/content-providers.html">content
56779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainprovider</a>. A content provider is an optional component that exposes read/write access to
57779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainyour application data, subject to whatever restrictions you want to impose. For more information
58779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainabout using content providers, see the
59779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<a href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers</a>
60779de5c040ab53e0dba9f7a21a236209a376f548Scott Maindocumentation.
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</p>
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
63779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
64779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
65779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
66779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h2 id="pref">Using Shared Preferences</h2>
67779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
68779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>The {@link android.content.SharedPreferences} class provides a general framework that allows you
69779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainto save and retrieve persistent key-value pairs of primitive data types. You can use {@link
70779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.SharedPreferences} to save any primitive data: booleans, floats, ints, longs, and
71779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainstrings. This data will persist across user sessions (even if your application is killed).</p>
72779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
73779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox-wrapper">
74779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox">
75779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h3>User Preferences</h3>
76779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Shared preferences are not strictly for saving "user preferences," such as what ringtone a
77779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainuser has chosen. If you're interested in creating user preferences for your application, see {@link
78779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.preference.PreferenceActivity}, which provides an Activity framework for you to create
79779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainuser preferences, which will be automatically persisted (using shared preferences).</p>
80779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div>
81779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div>
82779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
83779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>To get a {@link android.content.SharedPreferences} object for your application, use one of
84779de5c040ab53e0dba9f7a21a236209a376f548Scott Maintwo methods:</p>
85779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<ul>
86779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>{@link android.content.Context#getSharedPreferences(String,int)
87779de5c040ab53e0dba9f7a21a236209a376f548Scott MaingetSharedPreferences()} - Use this if you need multiple preferences files identified by name,
88779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainwhich you specify with the first parameter.</li>
89779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>{@link android.app.Activity#getPreferences(int) getPreferences()} - Use this if you need
90779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainonly one preferences file for your Activity. Because this will be the only preferences file
91779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfor your Activity, you don't supply a name.</li>
92779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</ul>
93779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
94779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>To write values:</p>
95779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<ol>
96779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>Call {@link android.content.SharedPreferences#edit()} to get a {@link
97779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.SharedPreferences.Editor}.</li>
98779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>Add values with methods such as {@link
99779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.SharedPreferences.Editor#putBoolean(String,boolean) putBoolean()} and {@link
100779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.SharedPreferences.Editor#putString(String,String) putString()}.</li>
101779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>Commit the new values with {@link android.content.SharedPreferences.Editor#commit()}</li>
102779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</ol>
103779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
104779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>To read values, use {@link android.content.SharedPreferences} methods such as {@link
105779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.SharedPreferences#getBoolean(String,boolean) getBoolean()} and {@link
106779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.SharedPreferences#getString(String,String) getString()}.</p>
107779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<p>
109779de5c040ab53e0dba9f7a21a236209a376f548Scott MainHere is an example that saves a preference for silent keypress mode in a
1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectcalculator:
1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</p>
1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<pre>
1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class Calc extends Activity {
115779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    public static final String PREFS_NAME = "MyPrefsFile";
1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    &#64;Override
118c4367e54e41f4e7a6c79b60dd80e66c9e6fdcfc3Scott Main    protected void onCreate(Bundle state){
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       super.onCreate(state);
120779de5c040ab53e0dba9f7a21a236209a376f548Scott Main       . . .
121779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       // Restore preferences
1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       boolean silent = settings.getBoolean("silentMode", false);
1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       setSilent(silent);
1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
127779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    &#64;Override
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    protected void onStop(){
1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project       super.onStop();
131779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
132779de5c040ab53e0dba9f7a21a236209a376f548Scott Main      // We need an Editor object to make preference changes.
133779de5c040ab53e0dba9f7a21a236209a376f548Scott Main      // All objects are from android.context.Context
1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      SharedPreferences.Editor editor = settings.edit();
1369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      editor.putBoolean("silentMode", mSilentMode);
1379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
138779de5c040ab53e0dba9f7a21a236209a376f548Scott Main      // Commit the edits!
1399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project      editor.commit();
1409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
1429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</pre>
1439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
147779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<a name="files"></a>
1489280c344651908feabdb9d34c5822293cf6ac256Scott Main<h2 id="filesInternal">Using the Internal Storage</h2>
1499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
150779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>You can save files directly on the device's internal storage. By default, files saved
151779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainto the internal storage are private to your application and other applications cannot access
152779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthem (nor can the user). When the user uninstalls your application, these files are removed.</p>
1539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
154779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>To create and write a private file to the internal storage:</p>
1559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
156779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<ol>
157779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>Call {@link android.content.Context#openFileOutput(String,int) openFileOutput()} with the
158779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainname of the file and the operating mode. This returns a {@link java.io.FileOutputStream}.</li>
159779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>Write to the file with {@link java.io.FileOutputStream#write(byte[]) write()}.</li>
160779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>Close the stream with {@link java.io.FileOutputStream#close()}.</li>
161779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</ol>
1629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
163779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>For example:</p>
1649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
165779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<pre>
166779de5c040ab53e0dba9f7a21a236209a376f548Scott MainString FILENAME = "hello_file";
167779de5c040ab53e0dba9f7a21a236209a376f548Scott MainString string = "hello world!";
168779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
169779de5c040ab53e0dba9f7a21a236209a376f548Scott MainFileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
170779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfos.write(string.getBytes());
171779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfos.close();
172779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</pre>
173779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
174779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>{@link android.content.Context#MODE_PRIVATE} will create the file (or replace a file of
175779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthe same name) and make it private to your application. Other modes available are: {@link
176779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.Context#MODE_APPEND}, {@link
177779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.Context#MODE_WORLD_READABLE}, and {@link
178779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.Context#MODE_WORLD_WRITEABLE}.</p>
179779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
180779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>To read a file from internal storage:</p>
181779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
182779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<ol>
183779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>Call {@link android.content.Context#openFileInput openFileInput()} and pass it the
184779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainname of the file to read. This returns a {@link java.io.FileInputStream}.</li>
185779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>Read bytes from the file with {@link java.io.FileInputStream#read(byte[],int,int)
186779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainread()}.</li>
187779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li>Then close the stream with  {@link java.io.FileInputStream#close()}.</li>
188779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</ol>
189779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
190779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p class="note"><strong>Tip:</strong> If you want to save a static file in your application at
191779de5c040ab53e0dba9f7a21a236209a376f548Scott Maincompile time, save the file in your project <code>res/raw/</code> directory. You can open it with
192779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.content.res.Resources#openRawResource(int) openRawResource()}, passing the {@code
193779de5c040ab53e0dba9f7a21a236209a376f548Scott MainR.raw.<em>&lt;filename&gt;</em>} resource ID. This method returns an {@link java.io.InputStream}
194779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthat you can use to read the file (but you cannot write to the original file).
1959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</p>
1969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
197779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
198779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h3 id="InternalCache">Saving cache files</h3>
199779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
200779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you'd like to cache some data, rather than store it persistently, you should use {@link
201779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.Context#getCacheDir()} to open a {@link
202779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainjava.io.File} that represents the internal directory where your application should save
203779de5c040ab53e0dba9f7a21a236209a376f548Scott Maintemporary cache files.</p>
204779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
205779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>When the device is
206779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainlow on internal storage space, Android may delete these cache files to recover space. However, you
207779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainshould not rely on the system to clean up these files for you. You should always maintain the cache
208779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfiles yourself and stay within a reasonable limit of space consumed, such as 1MB. When the user
209779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainuninstalls your application, these files are removed.</p>
210779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
211779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
212779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h3 id="InternalMethods">Other useful methods</h3>
213779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
214779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<dl>
215779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <dt>{@link android.content.Context#getFilesDir()}</dt>
216779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <dd>Gets the absolute path to the filesystem directory where your internal files are saved.</dd>
217779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <dt>{@link android.content.Context#getDir(String,int) getDir()}</dt>
218779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <dd>Creates (or opens an existing) directory within your internal storage space.</dd>
219779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <dt>{@link android.content.Context#deleteFile(String) deleteFile()}</dt>
220779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <dd>Deletes a file saved on the internal storage.</dd>
221779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <dt>{@link android.content.Context#fileList()}</dt>
222779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    <dd>Returns an array of files currently saved by your application.</dd>
223779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</dl>
224779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
225779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
226779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
227779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
2289280c344651908feabdb9d34c5822293cf6ac256Scott Main<h2 id="filesExternal">Using the External Storage</h2>
229779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
230779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Every Android-compatible device supports a shared "external storage" that you can use to
231779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainsave files. This can be a removable storage media (such as an SD card) or an internal
232779de5c040ab53e0dba9f7a21a236209a376f548Scott Main(non-removable) storage. Files saved to the external storage are world-readable and can
233779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainbe modified by the user when they enable USB mass storage to transfer files on a computer.</p>
234779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
235779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p class="caution"><strong>Caution:</strong> External files can disappear if the user mounts the
236779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainexternal storage on a computer or removes the media, and there's no security enforced upon files you
237779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainsave to the external storage. All applications can read and write files placed on the external
238779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainstorage and the user can remove them.</p>
239779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
240779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
241a90eb8fec1c67177b614b945bcc4a4b14aaabaffScott Main<h3 id="MediaAvail">Checking media availability</h3>
242779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
243779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Before you do any work with the external storage, you should always call {@link
244779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStorageState()} to check whether the media is available. The
245779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainmedia might be mounted to a computer, missing, read-only, or in some other state. For example,
246779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainhere's how you can check the availability:</p>
247779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
248779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<pre>
249779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainboolean mExternalStorageAvailable = false;
250779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainboolean mExternalStorageWriteable = false;
251779de5c040ab53e0dba9f7a21a236209a376f548Scott MainString state = Environment.getExternalStorageState();
252779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
253779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainif (Environment.MEDIA_MOUNTED.equals(state)) {
254779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    // We can read and write the media
255779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    mExternalStorageAvailable = mExternalStorageWriteable = true;
256779de5c040ab53e0dba9f7a21a236209a376f548Scott Main} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
257779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    // We can only read the media
258779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    mExternalStorageAvailable = true;
259779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    mExternalStorageWriteable = false;
260779de5c040ab53e0dba9f7a21a236209a376f548Scott Main} else {
261779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    // Something else is wrong. It may be one of many other states, but all we need
262779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    //  to know is we can neither read nor write
263779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    mExternalStorageAvailable = mExternalStorageWriteable = false;
264779de5c040ab53e0dba9f7a21a236209a376f548Scott Main}
265779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</pre>
266779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
267779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>This example checks whether the external storage is available to read and write. The
268779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.os.Environment#getExternalStorageState()} method returns other states that you
269779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainmight want to check, such as whether the media is being shared (connected to a computer), is missing
270779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainentirely, has been removed badly, etc. You can use these to notify the user with more information
271779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainwhen your application needs to access the media.</p>
272779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
273779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
274a90eb8fec1c67177b614b945bcc4a4b14aaabaffScott Main<h3 id="AccessingExtFiles">Accessing files on external storage</h3>
275779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
276779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 8 or greater, use {@link
277779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.Context#getExternalFilesDir(String) getExternalFilesDir()} to open a {@link
278779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainjava.io.File} that represents the external storage directory where you should save your
279779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfiles. This method takes a <code>type</code> parameter that specifies the type of subdirectory you
280779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainwant, such as {@link android.os.Environment#DIRECTORY_MUSIC} and
281779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.os.Environment#DIRECTORY_RINGTONES} (pass <code>null</code> to receive
282779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthe root of your application's file directory). This method will create the
283779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainappropriate directory if necessary. By specifying the type of directory, you
284779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainensure that the Android's media scanner will properly categorize your files in the system (for
285779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainexample, ringtones are identified as ringtones and not music). If the user uninstalls your
286779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainapplication, this directory and all its contents will be deleted.</p>
287779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
288779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 7 or lower, use {@link
289779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStorageDirectory()}, to open a {@link
290779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainjava.io.File} representing the root of the external storage. You should then write your data in the
291779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfollowing directory:</p>
292779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<pre class="no-pretty-print classic">
293779de5c040ab53e0dba9f7a21a236209a376f548Scott Main/Android/data/<em>&lt;package_name&gt;</em>/files/
294779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</pre>
295779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>The {@code <em>&lt;package_name&gt;</em>} is your Java-style package name, such as "{@code
296779de5c040ab53e0dba9f7a21a236209a376f548Scott Maincom.example.android.app}". If the user's device is running API Level 8 or greater and they
297779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainuninstall your application, this directory and all its contents will be deleted.</p>
298779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
299779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
300779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox-wrapper" style="margin-top:3em">
301779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox">
302779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
303779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h4>Hiding your files from the Media Scanner</h4>
304779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
305779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Include an empty file named {@code .nomedia} in your external files directory (note the dot
306779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainprefix in the filename). This will prevent Android's media scanner from reading your media
307779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfiles and including them in apps like Gallery or Music.</p>
308779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
309779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div>
310779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div>
311779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
312779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
313a90eb8fec1c67177b614b945bcc4a4b14aaabaffScott Main<h3 id="SavingSharedFiles">Saving files that should be shared</h3>
314779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
315779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you want to save files that are not specific to your application and that should <em>not</em>
316779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainbe deleted when your application is uninstalled, save them to one of the public directories on the
317779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainexternal storage. These directories lay at the root of the external storage, such as {@code
318779de5c040ab53e0dba9f7a21a236209a376f548Scott MainMusic/}, {@code Pictures/}, {@code Ringtones/}, and others.</p>
319779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
320779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>In API Level 8 or greater, use {@link
321779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStoragePublicDirectory(String)
322779de5c040ab53e0dba9f7a21a236209a376f548Scott MaingetExternalStoragePublicDirectory()}, passing it the type of public directory you want, such as
323779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.os.Environment#DIRECTORY_MUSIC}, {@link android.os.Environment#DIRECTORY_PICTURES},
324779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.os.Environment#DIRECTORY_RINGTONES}, or others. This method will create the
325779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainappropriate directory if necessary.</p>
326779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
327779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 7 or lower, use {@link
328779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStorageDirectory()} to open a {@link java.io.File} that represents
329779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthe root of the external storage, then save your shared files in one of the following
330779de5c040ab53e0dba9f7a21a236209a376f548Scott Maindirectories:</p>
331779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
332779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<ul class="nolist"></li>
333779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li><code>Music/</code> - Media scanner classifies all media found here as user music.</li>
334779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li><code>Podcasts/</code> - Media scanner classifies all media found here as a podcast.</li>
335779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li><code>Ringtones/ </code> - Media scanner classifies all media found here as a ringtone.</li>
336779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li><code>Alarms/</code> - Media scanner classifies all media found here as an alarm sound.</li>
337779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li><code>Notifications/</code> - Media scanner classifies all media found here as a notification
338779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainsound.</li>
339779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li><code>Pictures/</code> - All photos (excluding those taken with the camera).</li>
340779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li><code>Movies/</code> - All movies (excluding those taken with the camcorder).</li>
341779de5c040ab53e0dba9f7a21a236209a376f548Scott Main  <li><code>Download/</code> - Miscellaneous downloads.</li>
342779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</ul>
343779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
344779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
345779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h3 id="ExternalCache">Saving cache files</h3>
346779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
347779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 8 or greater, use {@link
348779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.Context#getExternalCacheDir()} to open a {@link java.io.File} that represents the
349779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainexternal storage directory where you should save cache files. If the user uninstalls your
350779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainapplication, these files will be automatically deleted. However, during the life of your
351779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainapplication, you should manage these cache files and remove those that aren't needed in order to
352779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainpreserve file space.</p>
353779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
354779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 7 or lower, use {@link
355779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStorageDirectory()} to open a {@link java.io.File} that represents
356779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthe root of the external storage, then write your cache data in the following directory:</p>
357779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<pre class="no-pretty-print classic">
358779de5c040ab53e0dba9f7a21a236209a376f548Scott Main/Android/data/<em>&lt;package_name&gt;</em>/cache/
359779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</pre>
360779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>The {@code <em>&lt;package_name&gt;</em>} is your Java-style package name, such as "{@code
361779de5c040ab53e0dba9f7a21a236209a376f548Scott Maincom.example.android.app}".</p>
362779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
363779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
364779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
365779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h2 id="db">Using Databases</h2>
366779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
367779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Android provides full support for <a href="http://www.sqlite.org/">SQLite</a> databases.
368779de5c040ab53e0dba9f7a21a236209a376f548Scott MainAny databases you create will be accessible by name to any
369779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainclass in the application, but not outside the application.</p>
370779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
371779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>The recommended method to create a new SQLite database is to create a subclass of {@link
372779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.database.sqlite.SQLiteOpenHelper} and override the {@link
373779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate()} method, in which you
374779de5c040ab53e0dba9f7a21a236209a376f548Scott Maincan execute a SQLite command to create tables in the database. For example:</p>
375779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
376779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<pre>
377c4367e54e41f4e7a6c79b60dd80e66c9e6fdcfc3Scott Mainpublic class DictionaryOpenHelper extends SQLiteOpenHelper {
378779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
379779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    private static final int DATABASE_VERSION = 2;
380779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    private static final String DICTIONARY_TABLE_NAME = "dictionary";
381779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    private static final String DICTIONARY_TABLE_CREATE =
382779de5c040ab53e0dba9f7a21a236209a376f548Scott Main                "CREATE TABLE " + DICTIONARY_TABLE_NAME + " (" +
383779de5c040ab53e0dba9f7a21a236209a376f548Scott Main                KEY_WORD + " TEXT, " +
384779de5c040ab53e0dba9f7a21a236209a376f548Scott Main                KEY_DEFINITION + " TEXT);";
385779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
386779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    DictionaryOpenHelper(Context context) {
387779de5c040ab53e0dba9f7a21a236209a376f548Scott Main        super(context, DATABASE_NAME, null, DATABASE_VERSION);
388779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    }
389779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
390779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    &#64;Override
391779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    public void onCreate(SQLiteDatabase db) {
392779de5c040ab53e0dba9f7a21a236209a376f548Scott Main        db.execSQL(DICTIONARY_TABLE_CREATE);
393779de5c040ab53e0dba9f7a21a236209a376f548Scott Main    }
394779de5c040ab53e0dba9f7a21a236209a376f548Scott Main}
395779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</pre>
396779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
397779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>You can then get an instance of your {@link android.database.sqlite.SQLiteOpenHelper}
398779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainimplementation using the constructor you've defined. To write to and read from the database, call
399779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.database.sqlite.SQLiteOpenHelper#getWritableDatabase()} and {@link
400779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.database.sqlite.SQLiteOpenHelper#getReadableDatabase()}, respectively. These both return a
401779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.database.sqlite.SQLiteDatabase} object that represents the database and
402779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainprovides methods for SQLite operations.</p>
403779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
404779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox-wrapper">
405779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox">
406779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Android does not impose any limitations beyond the standard SQLite concepts. We do recommend
4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectincluding an autoincrement value key field that can be used as a unique ID to
4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectquickly find a record.  This is not required for private data, but if you
409779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainimplement a <a href="{@docRoot}guide/topics/providers/content-providers.html">content provider</a>,
410779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainyou must include a unique ID using the {@link android.provider.BaseColumns#_ID BaseColumns._ID}
411779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainconstant.
412779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</p>
413779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div>
414779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div>
415779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
416779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>You can execute SQLite queries using the {@link android.database.sqlite.SQLiteDatabase}
417779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link
418779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.database.sqlite.SQLiteDatabase#query(boolean,String,String[],String,String[],String,String,String,String)
419779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainquery()} methods, which accept various query parameters, such as the table to query,
420779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthe projection, selection, columns, grouping, and others. For complex queries, such as
421779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthose that require column aliases, you should use
422779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.database.sqlite.SQLiteQueryBuilder}, which provides
423779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainseveral convienent methods for building queries.</p>
424779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
425779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Every SQLite query will return a {@link android.database.Cursor} that points to all the rows
426779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfound by the query. The {@link android.database.Cursor} is always the mechanism with which
427779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainyou can navigate results from a database query and read rows and columns.</p>
428779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
429779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>For sample apps that demonstrate how to use SQLite databases in Android, see the
430779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<a href="{@docRoot}resources/samples/NotePad/index.html">Note Pad</a> and
431779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<a href="{@docRoot}resources/samples/SearchableDictionary/index.html">Searchable Dictionary</a>
432779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainapplications.</p>
433779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
434779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
435779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h3 id="dbDebugging">Database debugging</h3>
436779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
437779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>The Android SDK includes a {@code sqlite3} database tool that allows you to browse
438779de5c040ab53e0dba9f7a21a236209a376f548Scott Maintable contents, run SQL commands, and perform other useful functions on SQLite
43950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Maindatabases.  See <a href="{@docRoot}tools/help/adb.html#sqlite">Examining sqlite3
440779de5c040ab53e0dba9f7a21a236209a376f548Scott Maindatabases from a remote shell</a> to learn how to run this tool.
4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</p>
4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
444779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
445779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
446779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
447779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h2 id="netw">Using a Network Connection</h2>
448779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
449779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<!-- TODO MAKE THIS USEFUL!! -->
450779de5c040ab53e0dba9f7a21a236209a376f548Scott Main
451779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>You can use the network (when it's available) to store and retrieve data on your own web-based
452779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainservices. To do network operations, use classes in the following packages:</p>
4539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<ul class="no-style">
4559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <li><code>{@link java.net java.net.*}</code></li>
4569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project  <li><code>{@link android.net android.net.*}</code></li>
4579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</ul>
458