Professional Documents
Culture Documents
myPreference = getSharedPreferences(prefName,Context.MODE_PRIVATE);
Now, any time you need to save a preference within your application, simply open a
SharedPreferences.Editor, assign a specific preference setting, and commit the
change.
Example:
Editor editor = myPreference.edit();
editor.putString(keyName,keyValue );
editor.commit();
myPreference.contains(keyname)
myPrefernce.getString(keyname)
To retrieve preference settings, simply retrieve SharedPreferences and read the values
back out:
An application can include raw files as resources. Raw files in application might
use include audio files, video files, and any other file formats you might need. All raw
resource files should be included in the /res/raw resource directory. All raw file
resources must have unique names, excluding the file suffix (meaning that file1.txt and
file1.dat would conflict). To access a raw file resource programmatically from within your
Activity class, simply use the openRawResource() method of the Resources class.
Example:
InputStream iFile = getResources().openRawResource(R.raw.file1);
There are times when you might want to include files within your application but
not have them compiled into application resources. Android provides a special project
directory called /assets for this purpose. This project directory resides at the same level
as the /res directory. Any files included in this directory are included as binary
resources, along with the application installation package, and are not compiled into the
application.
Uncompiled files, called application assets, are not accessible through the
getResources() method. Instead, you must use AssetManager to access files included
in the /assets directory.
Example:
Each Android application has its own private directory on the Android file system
for storing application files. In addition to all the familiar File ( java.io.File ) and Stream
( java.io.Stream ) classes available, you can access private application files and
directories by using the following Context class methods: fileList() , getFilesDir() ,
getDir() , openFileInput() , openFileOutput() , deleteFile() , and getFileStreamPath() .
These features can be helpful if your application needs to generate files or download
them from the Internet. Now that the help.xml layout file is complete, the
QuizHelpActivity class must be updated to read the quizhelp.txt file and place the
resulting text into the TextView control called helpText.
Raw resource files, such as the quizhelp.txt text file, are added to a project by simply
including them in the /raw resources project directory. This can be done by creating
them as a new file, dragging them in from a file-management tool, or any other way
youre accustomed to adding files to Android projects in Eclipse.