1 / 6

Android og persistens developer.android/guide/topics/data/data-storage.html

Android og persistens http://developer.android.com/guide/topics/data/data-storage.html. Your data storage options are the following: Shared Preferences Store private primitive data in key-value pairs. Internal Storage Store private data on the device memory.

echo-branch
Download Presentation

Android og persistens developer.android/guide/topics/data/data-storage.html

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android og persistenshttp://developer.android.com/guide/topics/data/data-storage.html • Your data storage options are the following: • Shared Preferences Store private primitive data in key-value pairs. • Internal Storage Store private data on the device memory. • External Storage Store public data on the shared external storage. • SQLite Databases Store structured data in a private database. • Network Connection Store data on the web with your own network server.

  2. SharedPreferences Skriv til SharedPreferences // Weneed an Editor object to makepreferencechanges.// All objectsare from android.context.Context • SharedPreferencessettings = getSharedPreferences("MyPrefsFile", 0); • SharedPreferences.Editoreditor = settings.edit(); • editor.putBoolean("silentMode", mSilentMode); Læs fra SharedPreferences • SharedPreferencessettings = getSharedPreferences("MyPrefsFile", 0); • booleansilent = settings.getBoolean("silentMode", false); • setSilent(silent);

  3. Tekstfiler i Android (java) Skriv på tekstfil • FileOutputStreamoutStream = openFileOutput("myfiletext",Context.MODE_PRIVATE); • PrintWriteroutTextStream = newPrintWriter(outStream); • outTextStream.println("En tekst"); • outTextStream.close(); Læs fra tekstfil • FileInputStreaminFileStream = openFileInput("myfiletext"); • InputStreamReaderinReader = newInputStreamReader(inFileStream); • BufferedReaderbuffReader = newBufferedReader(inReader); • String text; • text = (String) buffReader.readLine(); • buffReader.close();

  4. Serialisering af java-Objekter For at serialisere skal man implementere SerializableKlassen skal desuden forsynes med en unique ID • import java.io.Serializable; • public classBusinessModelimplementsSerializable { • private static final long serialVersionUID = -2255373015564100242L; • ………… • }

  5. Filer og java-Objekter Skriv objekt til fil • FileOutputStreamoutFileStream = openFileOutput("myfileobjects”,Context.MODE_PRIVATE); • ObjectOutputStreamoutObjectStream = newObjectOutputStream(outFileStream); • StringsimpleObject = "Hej "+(i+1); • outObjectStream.writeObject(simpleObject); • outTextStream.close(); Læs objekt fra fil • FileInputStreaminStream = openFileInput("myfileobjects"); • ObjectInputStreaminObjectStream = newObjectInputStream(inStream); • String text; • String simpleObject; • simpleObject = (String) inObjectStream.readObject(); • inObjectStream.close(); Check for exceptionEOFException

  6. public directories on the external storage • Music/ - Media scanner classifies all media found here as user music. • Podcasts/ - Media scanner classifies all media found here as a podcast. • Ringtones/ - Media scanner classifies all media found here as a ringtone. • Alarms/ - Media scanner classifies all media found here as an alarm sound. • Notifications/ - Media scanner classifies all media found here as a notification sound. • Pictures/ - All photos (excluding those taken with the camera). • Movies/ - All movies (excluding those taken with the camcorder). • Download/ - Miscellaneous downloads.

More Related