Лекция Android. Хранение данных

  • Published on
    16-Jun-2015

  • View
    2.418

  • Download
    0

Embed Size (px)

DESCRIPTION

android . , .

Transcript

  • 1. Android

2. Shared preferences () 19:58 - 2 41 3. Shared preferences () - 19:58 3 41 4. Shared preferences () - 19:58 4 41 5. Shared preferences () - SQLite 19:58 5 41 6. (Shared preferences) SharedPreferences : boolean, float, int, long string.19:586 41 7. (Shared preferences) SharedPreferences : boolean, float, int, long string. -. String.19:587 41 8. (Shared preferences) SharedPreferences : boolean, float, int, long string. -. String. , .19:588 41 9. (Shared preferences) 2 : 19:58getSharedPreferences() - , , ( );9 41 10. (Shared preferences) 2 : getSharedPreferences() - , , ( );getPreferences() - , . .19:5810 41 11. (Shared preferences) SharedPreferences.Editor19:5811 41 12. (Shared preferences) SharedPreferences.Editor : putBoolean(String key, boolean value); putString(String key, String value);19:5812 41 13. (Shared preferences) SharedPreferences.Editor : putBoolean(String key, boolean value); putString(String key, String value); commit().19:5813 41 14. (Shared preferences) SharedPreferences.Editor : putBoolean(String key, boolean value); putString(String key, String value); commit(). : getBoolean(String key, boolean defValue); getString(String key, String defValue);19:5814 41 15. (Shared preferences) public class Calc extends Activity { public static final String PREFS_NAME = "MyPrefsFile"; @Override protected void onCreate(Bundle state) { super.onCreate(state); ... // SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); boolean silent = settings.getBoolean("silentMode", false); setSilent(silent); } @Override protected void onStop() { super.onStop(); // Editor SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("silentMode", mSilentMode); // ! editor.commit(); } } 19:5815 41 16. (Shared preferences) : 19:58 contains(String key) ;16 41 17. (Shared preferences) : contains(String key) ; Map getAll() ;19:5817 41 18. (Shared preferences) : contains(String key) ; Map getAll() ; registerOnSharedPreferenceChangeListener() callback, ;19:5818 41 19. (Shared preferences) : contains(String key) ; Map getAll() ; registerOnSharedPreferenceChangeListener() callback, ; clear() - SharedPreferences.Editor;19:5819 41 20. (Shared preferences) : contains(String key) ; Map getAll() ; registerOnSharedPreferenceChangeListener() callback, ; clear() - SharedPreferences.Editor; remove(String key) , commit().19:5820 41 21. - .19:5821 41 22. - . .19:5822 41 23. - . . FileOutputStream openFileOutput(String name, int mode).19:5823 41 24. - . . FileOutputStream openFileOutput(String name, int mode). write().19:5824 41 25. - . . FileOutputStream openFileOutput(String name, int mode). write(). close().19:5825 41 26. - . . FileOutputStream openFileOutput(String name, int mode). write(). close(). FileInputStream openFileInput(String name).19:5826 41 27. - . . FileOutputStream openFileOutput(String name, int mode). write(). close(). FileInputStream openFileInput(String name). read().19:5827 41 28. : 19:58 getCacheDir();28 41 29. : getCacheDir(); getFilesDir() ;19:5829 41 30. : getCacheDir(); getFilesDir() ; getDir() ( ) ;19:5830 41 31. : getCacheDir(); getFilesDir() ; getDir() ( ) ; deleteFile() ;19:5831 41 32. : getCacheDir(); getFilesDir() ; getDir() ( ) ; deleteFile() ; fileList() , .19:5832 41 33. SD- .19:5833 41 34. SD- . ( ) .19:5834 41 35. SD- . ( ) . : getExternalStorageState()19:5835 41 36. boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // mExternalStorageAvailable = mExternalStorageWriteable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // mExternalStorageAvailable = true; mExternalStorageWriteable = false; } else { // - . , // , , mExternalStorageAvailable = mExternalStorageWriteable = false; } 19:5836 41 37. File getExternalFilesDir(String type).19:5837 41 38. File getExternalFilesDir(String type). type : DIRECTORY_MUSIC, DIRECTORY_PODCASTS, DIRECTORY_RINGTONES, DIRECTORY_ALARMS, DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES, DIRECTORY_MOVIES null.19:5838 41 39. File getExternalFilesDir(String type). type : DIRECTORY_MUSIC, DIRECTORY_PODCASTS, DIRECTORY_RINGTONES, DIRECTORY_ALARMS, DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES, DIRECTORY_MOVIES null. File getExternalStoragePublicDirectory(String type).19:5839 41 40. File getExternalFilesDir(String type). type : DIRECTORY_MUSIC, DIRECTORY_PODCASTS, DIRECTORY_RINGTONES, DIRECTORY_ALARMS, DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES, DIRECTORY_MOVIES null. File getExternalStoragePublicDirectory(String type). File getExternalCacheDir()19:5840 41 41. PreferenceActivity API Level 11 PreferenceFragment : CheckBoxPreferenceListPreferenceEditTextPreference19:5841 41

Recommended

View more >