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— 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 @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 @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><filename></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 23504c63a4098293dd00aeaf561b05a33c04a8d7853Scott Main<p>It's possible that a device using a partition of the 23604c63a4098293dd00aeaf561b05a33c04a8d7853Scott Maininternal storage for the external storage may also offer an SD card slot. In this case, 23704c63a4098293dd00aeaf561b05a33c04a8d7853Scott Mainthe SD card is <em>not</em> part of the external storage and your app cannot access it (the extra 23804c63a4098293dd00aeaf561b05a33c04a8d7853Scott Mainstorage is intended only for user-provided media that the system scans).</p> 23904c63a4098293dd00aeaf561b05a33c04a8d7853Scott Main 24004c63a4098293dd00aeaf561b05a33c04a8d7853Scott Main<p class="caution"><strong>Caution:</strong> External storage can become unavailable if the user mounts the 241779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainexternal storage on a computer or removes the media, and there's no security enforced upon files you 242779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainsave to the external storage. All applications can read and write files placed on the external 243779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainstorage and the user can remove them.</p> 244779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 245779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 246a90eb8fec1c67177b614b945bcc4a4b14aaabaffScott Main<h3 id="MediaAvail">Checking media availability</h3> 247779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 248779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Before you do any work with the external storage, you should always call {@link 249779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStorageState()} to check whether the media is available. The 250779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainmedia might be mounted to a computer, missing, read-only, or in some other state. For example, 251779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainhere's how you can check the availability:</p> 252779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 253779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<pre> 254779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainboolean mExternalStorageAvailable = false; 255779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainboolean mExternalStorageWriteable = false; 256779de5c040ab53e0dba9f7a21a236209a376f548Scott MainString state = Environment.getExternalStorageState(); 257779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 258779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainif (Environment.MEDIA_MOUNTED.equals(state)) { 259779de5c040ab53e0dba9f7a21a236209a376f548Scott Main // We can read and write the media 260779de5c040ab53e0dba9f7a21a236209a376f548Scott Main mExternalStorageAvailable = mExternalStorageWriteable = true; 261779de5c040ab53e0dba9f7a21a236209a376f548Scott Main} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { 262779de5c040ab53e0dba9f7a21a236209a376f548Scott Main // We can only read the media 263779de5c040ab53e0dba9f7a21a236209a376f548Scott Main mExternalStorageAvailable = true; 264779de5c040ab53e0dba9f7a21a236209a376f548Scott Main mExternalStorageWriteable = false; 265779de5c040ab53e0dba9f7a21a236209a376f548Scott Main} else { 266779de5c040ab53e0dba9f7a21a236209a376f548Scott Main // Something else is wrong. It may be one of many other states, but all we need 267779de5c040ab53e0dba9f7a21a236209a376f548Scott Main // to know is we can neither read nor write 268779de5c040ab53e0dba9f7a21a236209a376f548Scott Main mExternalStorageAvailable = mExternalStorageWriteable = false; 269779de5c040ab53e0dba9f7a21a236209a376f548Scott Main} 270779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</pre> 271779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 272779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>This example checks whether the external storage is available to read and write. The 273779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.os.Environment#getExternalStorageState()} method returns other states that you 274779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainmight want to check, such as whether the media is being shared (connected to a computer), is missing 275779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainentirely, has been removed badly, etc. You can use these to notify the user with more information 276779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainwhen your application needs to access the media.</p> 277779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 278779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 279a90eb8fec1c67177b614b945bcc4a4b14aaabaffScott Main<h3 id="AccessingExtFiles">Accessing files on external storage</h3> 280779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 281779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 8 or greater, use {@link 282779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.Context#getExternalFilesDir(String) getExternalFilesDir()} to open a {@link 283779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainjava.io.File} that represents the external storage directory where you should save your 284779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfiles. This method takes a <code>type</code> parameter that specifies the type of subdirectory you 285779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainwant, such as {@link android.os.Environment#DIRECTORY_MUSIC} and 286779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.os.Environment#DIRECTORY_RINGTONES} (pass <code>null</code> to receive 287779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthe root of your application's file directory). This method will create the 288779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainappropriate directory if necessary. By specifying the type of directory, you 289779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainensure that the Android's media scanner will properly categorize your files in the system (for 290779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainexample, ringtones are identified as ringtones and not music). If the user uninstalls your 291779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainapplication, this directory and all its contents will be deleted.</p> 292779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 293779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 7 or lower, use {@link 294779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStorageDirectory()}, to open a {@link 295779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainjava.io.File} representing the root of the external storage. You should then write your data in the 296779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfollowing directory:</p> 297779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<pre class="no-pretty-print classic"> 298779de5c040ab53e0dba9f7a21a236209a376f548Scott Main/Android/data/<em><package_name></em>/files/ 299779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</pre> 300779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>The {@code <em><package_name></em>} is your Java-style package name, such as "{@code 301779de5c040ab53e0dba9f7a21a236209a376f548Scott Maincom.example.android.app}". If the user's device is running API Level 8 or greater and they 302779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainuninstall your application, this directory and all its contents will be deleted.</p> 303779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 304779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 305779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox-wrapper" style="margin-top:3em"> 306779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox"> 307779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 308779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h4>Hiding your files from the Media Scanner</h4> 309779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 310779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Include an empty file named {@code .nomedia} in your external files directory (note the dot 311779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainprefix in the filename). This will prevent Android's media scanner from reading your media 312779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfiles and including them in apps like Gallery or Music.</p> 313779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 314779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div> 315779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div> 316779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 317779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 318a90eb8fec1c67177b614b945bcc4a4b14aaabaffScott Main<h3 id="SavingSharedFiles">Saving files that should be shared</h3> 319779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 320779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you want to save files that are not specific to your application and that should <em>not</em> 321779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainbe deleted when your application is uninstalled, save them to one of the public directories on the 322779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainexternal storage. These directories lay at the root of the external storage, such as {@code 323779de5c040ab53e0dba9f7a21a236209a376f548Scott MainMusic/}, {@code Pictures/}, {@code Ringtones/}, and others.</p> 324779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 325779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>In API Level 8 or greater, use {@link 326779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStoragePublicDirectory(String) 327779de5c040ab53e0dba9f7a21a236209a376f548Scott MaingetExternalStoragePublicDirectory()}, passing it the type of public directory you want, such as 328779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.os.Environment#DIRECTORY_MUSIC}, {@link android.os.Environment#DIRECTORY_PICTURES}, 329779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.os.Environment#DIRECTORY_RINGTONES}, or others. This method will create the 330779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainappropriate directory if necessary.</p> 331779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 332779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 7 or lower, use {@link 333779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStorageDirectory()} to open a {@link java.io.File} that represents 334779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthe root of the external storage, then save your shared files in one of the following 335779de5c040ab53e0dba9f7a21a236209a376f548Scott Maindirectories:</p> 336779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 337779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<ul class="nolist"></li> 338779de5c040ab53e0dba9f7a21a236209a376f548Scott Main <li><code>Music/</code> - Media scanner classifies all media found here as user music.</li> 339779de5c040ab53e0dba9f7a21a236209a376f548Scott Main <li><code>Podcasts/</code> - Media scanner classifies all media found here as a podcast.</li> 340779de5c040ab53e0dba9f7a21a236209a376f548Scott Main <li><code>Ringtones/ </code> - Media scanner classifies all media found here as a ringtone.</li> 341779de5c040ab53e0dba9f7a21a236209a376f548Scott Main <li><code>Alarms/</code> - Media scanner classifies all media found here as an alarm sound.</li> 342779de5c040ab53e0dba9f7a21a236209a376f548Scott Main <li><code>Notifications/</code> - Media scanner classifies all media found here as a notification 343779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainsound.</li> 344779de5c040ab53e0dba9f7a21a236209a376f548Scott Main <li><code>Pictures/</code> - All photos (excluding those taken with the camera).</li> 345779de5c040ab53e0dba9f7a21a236209a376f548Scott Main <li><code>Movies/</code> - All movies (excluding those taken with the camcorder).</li> 346779de5c040ab53e0dba9f7a21a236209a376f548Scott Main <li><code>Download/</code> - Miscellaneous downloads.</li> 347779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</ul> 348779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 349779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 350779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h3 id="ExternalCache">Saving cache files</h3> 351779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 352779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 8 or greater, use {@link 353779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.content.Context#getExternalCacheDir()} to open a {@link java.io.File} that represents the 354779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainexternal storage directory where you should save cache files. If the user uninstalls your 355779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainapplication, these files will be automatically deleted. However, during the life of your 356779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainapplication, you should manage these cache files and remove those that aren't needed in order to 357779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainpreserve file space.</p> 358779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 359779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>If you're using API Level 7 or lower, use {@link 360779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.os.Environment#getExternalStorageDirectory()} to open a {@link java.io.File} that represents 361779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthe root of the external storage, then write your cache data in the following directory:</p> 362779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<pre class="no-pretty-print classic"> 363779de5c040ab53e0dba9f7a21a236209a376f548Scott Main/Android/data/<em><package_name></em>/cache/ 364779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</pre> 365779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>The {@code <em><package_name></em>} is your Java-style package name, such as "{@code 366779de5c040ab53e0dba9f7a21a236209a376f548Scott Maincom.example.android.app}".</p> 367779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 368779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 369779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 370779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h2 id="db">Using Databases</h2> 371779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 372779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Android provides full support for <a href="http://www.sqlite.org/">SQLite</a> databases. 373779de5c040ab53e0dba9f7a21a236209a376f548Scott MainAny databases you create will be accessible by name to any 374779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainclass in the application, but not outside the application.</p> 375779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 376779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>The recommended method to create a new SQLite database is to create a subclass of {@link 377779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.database.sqlite.SQLiteOpenHelper} and override the {@link 378779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.database.sqlite.SQLiteOpenHelper#onCreate(SQLiteDatabase) onCreate()} method, in which you 379779de5c040ab53e0dba9f7a21a236209a376f548Scott Maincan execute a SQLite command to create tables in the database. For example:</p> 380779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 381779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<pre> 382c4367e54e41f4e7a6c79b60dd80e66c9e6fdcfc3Scott Mainpublic class DictionaryOpenHelper extends SQLiteOpenHelper { 383779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 384779de5c040ab53e0dba9f7a21a236209a376f548Scott Main private static final int DATABASE_VERSION = 2; 385779de5c040ab53e0dba9f7a21a236209a376f548Scott Main private static final String DICTIONARY_TABLE_NAME = "dictionary"; 386779de5c040ab53e0dba9f7a21a236209a376f548Scott Main private static final String DICTIONARY_TABLE_CREATE = 387779de5c040ab53e0dba9f7a21a236209a376f548Scott Main "CREATE TABLE " + DICTIONARY_TABLE_NAME + " (" + 388779de5c040ab53e0dba9f7a21a236209a376f548Scott Main KEY_WORD + " TEXT, " + 389779de5c040ab53e0dba9f7a21a236209a376f548Scott Main KEY_DEFINITION + " TEXT);"; 390779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 391779de5c040ab53e0dba9f7a21a236209a376f548Scott Main DictionaryOpenHelper(Context context) { 392779de5c040ab53e0dba9f7a21a236209a376f548Scott Main super(context, DATABASE_NAME, null, DATABASE_VERSION); 393779de5c040ab53e0dba9f7a21a236209a376f548Scott Main } 394779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 395779de5c040ab53e0dba9f7a21a236209a376f548Scott Main @Override 396779de5c040ab53e0dba9f7a21a236209a376f548Scott Main public void onCreate(SQLiteDatabase db) { 397779de5c040ab53e0dba9f7a21a236209a376f548Scott Main db.execSQL(DICTIONARY_TABLE_CREATE); 398779de5c040ab53e0dba9f7a21a236209a376f548Scott Main } 399779de5c040ab53e0dba9f7a21a236209a376f548Scott Main} 400779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</pre> 401779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 402779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>You can then get an instance of your {@link android.database.sqlite.SQLiteOpenHelper} 403779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainimplementation using the constructor you've defined. To write to and read from the database, call 404779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.database.sqlite.SQLiteOpenHelper#getWritableDatabase()} and {@link 405779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.database.sqlite.SQLiteOpenHelper#getReadableDatabase()}, respectively. These both return a 406779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.database.sqlite.SQLiteDatabase} object that represents the database and 407779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainprovides methods for SQLite operations.</p> 408779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 409779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox-wrapper"> 410779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<div class="sidebox"> 411779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Android does not impose any limitations beyond the standard SQLite concepts. We do recommend 4129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectincluding an autoincrement value key field that can be used as a unique ID to 4139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectquickly find a record. This is not required for private data, but if you 414779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainimplement a <a href="{@docRoot}guide/topics/providers/content-providers.html">content provider</a>, 415779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainyou must include a unique ID using the {@link android.provider.BaseColumns#_ID BaseColumns._ID} 416779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainconstant. 417779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</p> 418779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div> 419779de5c040ab53e0dba9f7a21a236209a376f548Scott Main</div> 420779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 421779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>You can execute SQLite queries using the {@link android.database.sqlite.SQLiteDatabase} 422779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link 423779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainandroid.database.sqlite.SQLiteDatabase#query(boolean,String,String[],String,String[],String,String,String,String) 424779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainquery()} methods, which accept various query parameters, such as the table to query, 425779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthe projection, selection, columns, grouping, and others. For complex queries, such as 426779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainthose that require column aliases, you should use 427779de5c040ab53e0dba9f7a21a236209a376f548Scott Main{@link android.database.sqlite.SQLiteQueryBuilder}, which provides 428779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainseveral convienent methods for building queries.</p> 429779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 430779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>Every SQLite query will return a {@link android.database.Cursor} that points to all the rows 431779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainfound by the query. The {@link android.database.Cursor} is always the mechanism with which 432779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainyou can navigate results from a database query and read rows and columns.</p> 433779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 434779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>For sample apps that demonstrate how to use SQLite databases in Android, see the 435779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<a href="{@docRoot}resources/samples/NotePad/index.html">Note Pad</a> and 436779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<a href="{@docRoot}resources/samples/SearchableDictionary/index.html">Searchable Dictionary</a> 437779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainapplications.</p> 438779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 439779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 440779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h3 id="dbDebugging">Database debugging</h3> 441779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 442779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>The Android SDK includes a {@code sqlite3} database tool that allows you to browse 443779de5c040ab53e0dba9f7a21a236209a376f548Scott Maintable contents, run SQL commands, and perform other useful functions on SQLite 44450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Maindatabases. See <a href="{@docRoot}tools/help/adb.html#sqlite">Examining sqlite3 445779de5c040ab53e0dba9f7a21a236209a376f548Scott Maindatabases from a remote shell</a> to learn how to run this tool. 4469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</p> 4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 449779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 450779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 451779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 452779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<h2 id="netw">Using a Network Connection</h2> 453779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 454779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<!-- TODO MAKE THIS USEFUL!! --> 455779de5c040ab53e0dba9f7a21a236209a376f548Scott Main 456779de5c040ab53e0dba9f7a21a236209a376f548Scott Main<p>You can use the network (when it's available) to store and retrieve data on your own web-based 457779de5c040ab53e0dba9f7a21a236209a376f548Scott Mainservices. To do network operations, use classes in the following packages:</p> 4589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project<ul class="no-style"> 4609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project <li><code>{@link java.net java.net.*}</code></li> 4619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project <li><code>{@link android.net android.net.*}</code></li> 4629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project</ul> 463