SlideShare a Scribd company logo
1 of 11
Download to read offline
Pemrograman
Bergerak
Shared Preferences and Settings
Program Studi : PJJ INFORMATIKA S1
Tatap Muka
Kode Matakuliah : 200301315
Disusun oleh : Riad Sahara, S.SI., M.T.
13
2022
2 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
DESKRIPSI MATERI PERTEMUAN 13
Materi Pertemuan 13 Shared Preferences and Settings
Deskripsi Materi Shared preferences allow you to store small amounts of primitive data as
key/value pairs in a file on the device. To get a handle to a preference file,
and to read, write, and manage preference data, use
the SharedPreferences class. The Android framework manages the shared
preferences file itself. The file is accessible to all the components of your
app, but it is not accessible to other apps. Apps often include settings that
allow users to modify app features and behaviors.
For example, some apps allow the user to set their home location, default
units for measurements, and other settings that apply to the entire app.
Users don't access settings frequently, because once a user changes a
setting, such as a home location, they rarely need to go back and change it
again.
Sub Capaian
Pembelajaran Mata
Kuliah (Sub CPMK)
Luaran yang diharapkan setelah mengikuti materi pada pertemuan ini
- Mahasiswa mampu memahami konsep dan implementasi dari
Shared Preferences dan Settings pada aplikasi Android yang akan
dikembangkan.
Deskrispsi Tugas Tugas dalam bentuk Kuis dengan tipe True/False, nilai maksimal dari Kuis
adalah 100 point.
Kontrak Perkuliahan Kehadiran Mahasiswa dihitung dengan parameter:
1. View dan Download Modul
2. Mengerjakan Kuis/Tugas
3. Posting/Reply Diskusi/Forum
Untuk Komposisi Penilaian:
1. Presensi Kehadiran : 10%
2. Tugas : 40%
3. UTS : 25%
4. UAS : 25%
2022
3 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
Pertemuan 13
Shared Preferences and Settings
13.1.Data Storage
Contents
• Android File System
• Internal Storage
• External Storage
• SQLite Database
• Other Storage Options
13.1.1. Storage Options
13.1.1.1. Storing data
● Shared Preferences—Private primitive data in key-value pairs
● Internal Storage—Private data on device memory
● External Storage—Public data on device or external storage
● SQLite Databases—Structured data in a private database
● Content Providers—Store privately and make available publicly
13.1.1.2. Storing data beyond Android
● Network Connection—On the web with your own server
● Cloud Backup—Back up app and user data in the cloud
● Firebase Realtime Database—Store and sync data with NoSQL cloud database across
clients in realtime
2022
4 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
13.1.2. Files
13.1.2.1. Android File System
● External storage -- Public directories
● Internal storage -- Private directories for just your app
Apps can browse the directory structure
Structure and operations similar to Linux and java.io
13.1.2.2. Internal storage
● Always available
● Uses device's filesystem
● Only your app can access files, unless explicitly set to be readable or writable
● On app uninstall, system removes all app's files from internal storage
13.1.2.3. External storage
● Not always available, can be removed
● Uses device's file system or physically external storage like SD card
● World-readable, so any app can read
● On uninstall, system does not remove files private to app
13.1.2.4. When to use internal/external storage
Internal is best when
● you want to be sure that neither the user nor other apps can access your files
External is best for files that
● don't require access restrictions and for
● you want to share with other apps
● you allow the user to access with a computer
13.1.2.5. Save user's file in shared storage
● Save new files that the user acquires through your app to a public directory where other apps
can access them and the user can easily copy them from the device
2022
5 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
● Save external files in public directories
13.1.3. Internal Storage
13.1.3.1. Internal Storage
● Uses private directories just for your app
● App always has permission to read/write
● Permanent storage directory—getFilesDir()
● Temporary storage directory—getCacheDir()
13.1.3.2. Creating a file
File file = new File(
context.getFilesDir(), filename);
Use standard java.io file operators or streams to interact with files
13.1.3.3. External Storage
● On device or SD card
● Set permissions in Android Manifest
○ Write permission includes read permission
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
13.1.3.4. Always check availability of storage
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
2022
6 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
return false;
}
13.1.3.5. Example external public directories
● DIRECTORY_ALARMS and DIRECTORY_RINGTONES
For audio files to use as alarms and ringtones
● DIRECTORY_DOCUMENTS
For documents that have been created by the user
● DIRECTORY_DOWNLOADS
For files that have been downloaded by the user
13.1.3.6. Accessing public external directories
• Get a path getExternalStoragePublicDirectory()
• Create file
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(path, "DemoPicture.jpg");
13.1.3.7. How much storage left?
● If there is not enough space, throws IOException
● If you know the size of the file, check against space
○ getFreeSpace()
○ getTotalSpace().
● If you do not know how much space is needed
○ try/catch IOException
13.1.3.8. Delete files no longer needed
● External storage
myFile.delete();
2022
7 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
● Internal storage
myContext.deleteFile(fileName);
13.1.3.9. Do not delete the user's files!
When the user uninstalls your app, your app's private storage directory and all its contents are deleted
Do not use private storage for content that belongs to the user!
For example
● Photos captured or edited with your app
● Music the user has purchased with your app
13.1.4. Shared Preferences & SQLite Database
13.1.4.1. SQLite Database
● Ideal for repeating or structured data, such as contacts
● Android provides SQL-like database
● Covered in following chapters and practicals
○ SQLite Primer
○ Introduction to SQLite Databases
○ SQLite Data Storage Practical
○ Searching an SQLite Database Practical
13.1.4.2. Shared Preferences
● Read and write small amounts of primitive data as key/value pairs to a file on the device
storage
● Covered in later chapter and practical
○ Shared Preferences
13.1.5. Other Storage Options
13.1.5.1. Use Firebase to store and share data
Store and sync data with the Firebase cloud database
2022
8 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
Data is synced across all clients, and remains available when your app goes offline
firebase.google.com/docs/database/
13.1.5.2. Firebase Realtime Database
● Connected apps share data
● Hosted in the cloud
● Data is stored as JSON
● Data is synchronized in realtime to every connected client
2022
9 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
13.1.5.3. Network Connection
● You can use the network (when it's available) to store and retrieve data on your own web-
based services
● Use classes in the following packages
○ java.net.*
○ android.net.*
13.1.5.4. Backing up data
● Auto Backup for 6.0 (API level 23) and higher
● Automatically back up app data to the cloud
● No code required and free
● Customize and configure auto backup for your app
● See Configuring Auto Backup for Apps
13.1.5.5. Backup API for Android 5.1 (API level 22)
• Register for Android Backup Service to get a Backup Service Key
• Configure Manifest to use Backup Service
• Create a backup agent by extending the BackupAgentHelper class
• Request backups when data has changed
More info and sample code: Using the Backup AP and Data Backup
13.2.Learn more about files
● Saving Files
● getExternalFilesDir() documentation and code samples
● getExternalStoragePublicDirectory() documentation and code samples
● java.io.File class
● Oracle's Java I/O Tutorial
2022
10 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
13.3.Learn more about backups
● Configuring Auto Backup for Apps
● Using the Backup API
● Data Backup
Untuk modul lengkapnya silahkan lihat di modul versi PPT ya
2022
11 Pemrograman Bergerak Universitas Siber Asia
Riad Sahara, S.SI., M.T. http://www.unsia.ac.id
DAFTAR PUSTAKA
[1] Google, D. (2021, 09 24). Dasar-Dasar Developer Android. Retrieved from Google Developers:
https://developers.google.com/training/courses/android-fundamentals?hl=id

More Related Content

Similar to Pertemuan 13 - Shared Preferences and Settings - Word - Salin.pdf

Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behesteeHussain Behestee
 
Google android white paper
Google android white paperGoogle android white paper
Google android white paperSravan Reddy
 
Owasp Mobile Risk M2 : Insecure Data Storage : null/OWASP/G4H Bangalore Aug 2014
Owasp Mobile Risk M2 : Insecure Data Storage : null/OWASP/G4H Bangalore Aug 2014Owasp Mobile Risk M2 : Insecure Data Storage : null/OWASP/G4H Bangalore Aug 2014
Owasp Mobile Risk M2 : Insecure Data Storage : null/OWASP/G4H Bangalore Aug 2014Anant Shrivastava
 
03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)TECOS
 
Android File Management Presentation.pptx
Android File Management Presentation.pptxAndroid File Management Presentation.pptx
Android File Management Presentation.pptxvuqaxuly
 
Android File Management Presentation.pptx
Android File Management Presentation.pptxAndroid File Management Presentation.pptx
Android File Management Presentation.pptxvuqaxuly
 
Third-party App Stores on Android.pptx.pdf
Third-party App Stores on Android.pptx.pdfThird-party App Stores on Android.pptx.pdf
Third-party App Stores on Android.pptx.pdfAayush Gupta
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applicationsTOPS Technologies
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android Aakash Ugale
 
Android Security and Peneteration Testing
Android Security and Peneteration TestingAndroid Security and Peneteration Testing
Android Security and Peneteration TestingSurabaya Blackhat
 
Cloud Storage System like Dropbox
Cloud Storage System like DropboxCloud Storage System like Dropbox
Cloud Storage System like DropboxIRJET Journal
 
Android Architecture, Environment, and Components.pptx
Android Architecture, Environment, and Components.pptxAndroid Architecture, Environment, and Components.pptx
Android Architecture, Environment, and Components.pptxHasanulFahmi2
 
Integrity Auditing Of Dynamic Cloud Data With Group User Revocation
Integrity Auditing Of Dynamic Cloud Data With Group User RevocationIntegrity Auditing Of Dynamic Cloud Data With Group User Revocation
Integrity Auditing Of Dynamic Cloud Data With Group User RevocationJSPM's JSCOE , Pune Maharashtra.
 
Implementation of sql server based on sqlite engine on
Implementation of sql server based on sqlite engine onImplementation of sql server based on sqlite engine on
Implementation of sql server based on sqlite engine oneSAT Publishing House
 
[Wroclaw #1] Android Security Workshop
[Wroclaw #1] Android Security Workshop[Wroclaw #1] Android Security Workshop
[Wroclaw #1] Android Security WorkshopOWASP
 

Similar to Pertemuan 13 - Shared Preferences and Settings - Word - Salin.pdf (20)

Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behestee
 
Google android white paper
Google android white paperGoogle android white paper
Google android white paper
 
Owasp Mobile Risk M2 : Insecure Data Storage : null/OWASP/G4H Bangalore Aug 2014
Owasp Mobile Risk M2 : Insecure Data Storage : null/OWASP/G4H Bangalore Aug 2014Owasp Mobile Risk M2 : Insecure Data Storage : null/OWASP/G4H Bangalore Aug 2014
Owasp Mobile Risk M2 : Insecure Data Storage : null/OWASP/G4H Bangalore Aug 2014
 
Mobile web development
Mobile web developmentMobile web development
Mobile web development
 
Web storage
Web storage Web storage
Web storage
 
03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)
 
Android File Management Presentation.pptx
Android File Management Presentation.pptxAndroid File Management Presentation.pptx
Android File Management Presentation.pptx
 
Android File Management Presentation.pptx
Android File Management Presentation.pptxAndroid File Management Presentation.pptx
Android File Management Presentation.pptx
 
Third-party App Stores on Android.pptx.pdf
Third-party App Stores on Android.pptx.pdfThird-party App Stores on Android.pptx.pdf
Third-party App Stores on Android.pptx.pdf
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applications
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Android Security and Peneteration Testing
Android Security and Peneteration TestingAndroid Security and Peneteration Testing
Android Security and Peneteration Testing
 
Cloud Storage System like Dropbox
Cloud Storage System like DropboxCloud Storage System like Dropbox
Cloud Storage System like Dropbox
 
Android Architecture, Environment, and Components.pptx
Android Architecture, Environment, and Components.pptxAndroid Architecture, Environment, and Components.pptx
Android Architecture, Environment, and Components.pptx
 
Auditing Cloud Data With Group
Auditing Cloud Data With GroupAuditing Cloud Data With Group
Auditing Cloud Data With Group
 
Integrity Auditing Of Dynamic Cloud Data With Group User Revocation
Integrity Auditing Of Dynamic Cloud Data With Group User RevocationIntegrity Auditing Of Dynamic Cloud Data With Group User Revocation
Integrity Auditing Of Dynamic Cloud Data With Group User Revocation
 
Implementation of sql server based on sqlite engine on
Implementation of sql server based on sqlite engine onImplementation of sql server based on sqlite engine on
Implementation of sql server based on sqlite engine on
 
[Wroclaw #1] Android Security Workshop
[Wroclaw #1] Android Security Workshop[Wroclaw #1] Android Security Workshop
[Wroclaw #1] Android Security Workshop
 
Storage 8
Storage   8Storage   8
Storage 8
 
Imd 113
Imd 113Imd 113
Imd 113
 

More from HendroGunawan8

Estetika Humanisme Diskusi Modul Part Ke-4 (DipulihkanOtomatis).pdf
Estetika Humanisme Diskusi Modul Part Ke-4 (DipulihkanOtomatis).pdfEstetika Humanisme Diskusi Modul Part Ke-4 (DipulihkanOtomatis).pdf
Estetika Humanisme Diskusi Modul Part Ke-4 (DipulihkanOtomatis).pdfHendroGunawan8
 
Estetika Humanisme Diskusi Video Sesi Ke-4.pdf
Estetika Humanisme Diskusi Video Sesi Ke-4.pdfEstetika Humanisme Diskusi Video Sesi Ke-4.pdf
Estetika Humanisme Diskusi Video Sesi Ke-4.pdfHendroGunawan8
 
Pengolahan Citra Diskusi Pertemuan Ke-4.pdf
Pengolahan Citra Diskusi Pertemuan Ke-4.pdfPengolahan Citra Diskusi Pertemuan Ke-4.pdf
Pengolahan Citra Diskusi Pertemuan Ke-4.pdfHendroGunawan8
 
Diskusi Modul Sistem Pakar Sesi Ke-4.pdf
Diskusi Modul Sistem Pakar Sesi Ke-4.pdfDiskusi Modul Sistem Pakar Sesi Ke-4.pdf
Diskusi Modul Sistem Pakar Sesi Ke-4.pdfHendroGunawan8
 
Diskusi PPT Sistem Pakar Sesi Ke-4 Simple Naïve Bayesian Classifier .pdf
Diskusi PPT Sistem Pakar Sesi Ke-4 Simple Naïve Bayesian Classifier .pdfDiskusi PPT Sistem Pakar Sesi Ke-4 Simple Naïve Bayesian Classifier .pdf
Diskusi PPT Sistem Pakar Sesi Ke-4 Simple Naïve Bayesian Classifier .pdfHendroGunawan8
 
Estetika Humanisme Diskusi Modul Part Ke-3.pdf
Estetika Humanisme Diskusi Modul Part Ke-3.pdfEstetika Humanisme Diskusi Modul Part Ke-3.pdf
Estetika Humanisme Diskusi Modul Part Ke-3.pdfHendroGunawan8
 
Diskusi Modul Sistem Pakar Sesi Ke-3.pdf
Diskusi Modul Sistem Pakar Sesi Ke-3.pdfDiskusi Modul Sistem Pakar Sesi Ke-3.pdf
Diskusi Modul Sistem Pakar Sesi Ke-3.pdfHendroGunawan8
 
Diskusi Modul Sistem Pakar Sesi Ke-3.pdf
Diskusi Modul Sistem Pakar Sesi Ke-3.pdfDiskusi Modul Sistem Pakar Sesi Ke-3.pdf
Diskusi Modul Sistem Pakar Sesi Ke-3.pdfHendroGunawan8
 
Estetika Humanisme Diskusi Video Sesi Ke-3 (DipulihkanOtomatis).pdf
Estetika Humanisme Diskusi Video Sesi Ke-3 (DipulihkanOtomatis).pdfEstetika Humanisme Diskusi Video Sesi Ke-3 (DipulihkanOtomatis).pdf
Estetika Humanisme Diskusi Video Sesi Ke-3 (DipulihkanOtomatis).pdfHendroGunawan8
 
Pengolahan Citra Diskusi Pertemuan Ke-2.pdf
Pengolahan Citra Diskusi Pertemuan Ke-2.pdfPengolahan Citra Diskusi Pertemuan Ke-2.pdf
Pengolahan Citra Diskusi Pertemuan Ke-2.pdfHendroGunawan8
 
Protokol dan prosedur yang menyediakan layanan komunikasi multimedia audio, v...
Protokol dan prosedur yang menyediakan layanan komunikasi multimedia audio, v...Protokol dan prosedur yang menyediakan layanan komunikasi multimedia audio, v...
Protokol dan prosedur yang menyediakan layanan komunikasi multimedia audio, v...HendroGunawan8
 
Estetika Humanisme Diskusi Modul Ke-2 Sesi Ke-2.pdf
Estetika Humanisme Diskusi Modul Ke-2 Sesi Ke-2.pdfEstetika Humanisme Diskusi Modul Ke-2 Sesi Ke-2.pdf
Estetika Humanisme Diskusi Modul Ke-2 Sesi Ke-2.pdfHendroGunawan8
 
Estetika Humanisme Diskusi Modul Ke-1 Pertemuan Ke-2.pdf
Estetika Humanisme Diskusi Modul Ke-1 Pertemuan Ke-2.pdfEstetika Humanisme Diskusi Modul Ke-1 Pertemuan Ke-2.pdf
Estetika Humanisme Diskusi Modul Ke-1 Pertemuan Ke-2.pdfHendroGunawan8
 
Estetika Humanisme Diskusi Video Sesi Ke-1.pdf
Estetika Humanisme Diskusi Video Sesi Ke-1.pdfEstetika Humanisme Diskusi Video Sesi Ke-1.pdf
Estetika Humanisme Diskusi Video Sesi Ke-1.pdfHendroGunawan8
 
Jaringan VOIP Ringkasan PTT Pertemuan Ke-1.pdf
Jaringan VOIP Ringkasan PTT Pertemuan Ke-1.pdfJaringan VOIP Ringkasan PTT Pertemuan Ke-1.pdf
Jaringan VOIP Ringkasan PTT Pertemuan Ke-1.pdfHendroGunawan8
 
PSTN adalah kumpulan jaringan telepon umum yang saling terhubung di seluruh d...
PSTN adalah kumpulan jaringan telepon umum yang saling terhubung di seluruh d...PSTN adalah kumpulan jaringan telepon umum yang saling terhubung di seluruh d...
PSTN adalah kumpulan jaringan telepon umum yang saling terhubung di seluruh d...HendroGunawan8
 
Pengolahan citra digital adalah teknologi visual yang digunakan untuk mengama...
Pengolahan citra digital adalah teknologi visual yang digunakan untuk mengama...Pengolahan citra digital adalah teknologi visual yang digunakan untuk mengama...
Pengolahan citra digital adalah teknologi visual yang digunakan untuk mengama...HendroGunawan8
 
Sistem pakar (expert system) adalah sistem yang berusaha mengadopsi pengetahu...
Sistem pakar (expert system) adalah sistem yang berusaha mengadopsi pengetahu...Sistem pakar (expert system) adalah sistem yang berusaha mengadopsi pengetahu...
Sistem pakar (expert system) adalah sistem yang berusaha mengadopsi pengetahu...HendroGunawan8
 
Estetika Humanisme Ringkasan Pertemuan 1.pdf
Estetika Humanisme Ringkasan Pertemuan 1.pdfEstetika Humanisme Ringkasan Pertemuan 1.pdf
Estetika Humanisme Ringkasan Pertemuan 1.pdfHendroGunawan8
 
Modul 15 MPTI - Presentasi Hasil Penelitian.docx
Modul 15 MPTI - Presentasi Hasil Penelitian.docxModul 15 MPTI - Presentasi Hasil Penelitian.docx
Modul 15 MPTI - Presentasi Hasil Penelitian.docxHendroGunawan8
 

More from HendroGunawan8 (20)

Estetika Humanisme Diskusi Modul Part Ke-4 (DipulihkanOtomatis).pdf
Estetika Humanisme Diskusi Modul Part Ke-4 (DipulihkanOtomatis).pdfEstetika Humanisme Diskusi Modul Part Ke-4 (DipulihkanOtomatis).pdf
Estetika Humanisme Diskusi Modul Part Ke-4 (DipulihkanOtomatis).pdf
 
Estetika Humanisme Diskusi Video Sesi Ke-4.pdf
Estetika Humanisme Diskusi Video Sesi Ke-4.pdfEstetika Humanisme Diskusi Video Sesi Ke-4.pdf
Estetika Humanisme Diskusi Video Sesi Ke-4.pdf
 
Pengolahan Citra Diskusi Pertemuan Ke-4.pdf
Pengolahan Citra Diskusi Pertemuan Ke-4.pdfPengolahan Citra Diskusi Pertemuan Ke-4.pdf
Pengolahan Citra Diskusi Pertemuan Ke-4.pdf
 
Diskusi Modul Sistem Pakar Sesi Ke-4.pdf
Diskusi Modul Sistem Pakar Sesi Ke-4.pdfDiskusi Modul Sistem Pakar Sesi Ke-4.pdf
Diskusi Modul Sistem Pakar Sesi Ke-4.pdf
 
Diskusi PPT Sistem Pakar Sesi Ke-4 Simple Naïve Bayesian Classifier .pdf
Diskusi PPT Sistem Pakar Sesi Ke-4 Simple Naïve Bayesian Classifier .pdfDiskusi PPT Sistem Pakar Sesi Ke-4 Simple Naïve Bayesian Classifier .pdf
Diskusi PPT Sistem Pakar Sesi Ke-4 Simple Naïve Bayesian Classifier .pdf
 
Estetika Humanisme Diskusi Modul Part Ke-3.pdf
Estetika Humanisme Diskusi Modul Part Ke-3.pdfEstetika Humanisme Diskusi Modul Part Ke-3.pdf
Estetika Humanisme Diskusi Modul Part Ke-3.pdf
 
Diskusi Modul Sistem Pakar Sesi Ke-3.pdf
Diskusi Modul Sistem Pakar Sesi Ke-3.pdfDiskusi Modul Sistem Pakar Sesi Ke-3.pdf
Diskusi Modul Sistem Pakar Sesi Ke-3.pdf
 
Diskusi Modul Sistem Pakar Sesi Ke-3.pdf
Diskusi Modul Sistem Pakar Sesi Ke-3.pdfDiskusi Modul Sistem Pakar Sesi Ke-3.pdf
Diskusi Modul Sistem Pakar Sesi Ke-3.pdf
 
Estetika Humanisme Diskusi Video Sesi Ke-3 (DipulihkanOtomatis).pdf
Estetika Humanisme Diskusi Video Sesi Ke-3 (DipulihkanOtomatis).pdfEstetika Humanisme Diskusi Video Sesi Ke-3 (DipulihkanOtomatis).pdf
Estetika Humanisme Diskusi Video Sesi Ke-3 (DipulihkanOtomatis).pdf
 
Pengolahan Citra Diskusi Pertemuan Ke-2.pdf
Pengolahan Citra Diskusi Pertemuan Ke-2.pdfPengolahan Citra Diskusi Pertemuan Ke-2.pdf
Pengolahan Citra Diskusi Pertemuan Ke-2.pdf
 
Protokol dan prosedur yang menyediakan layanan komunikasi multimedia audio, v...
Protokol dan prosedur yang menyediakan layanan komunikasi multimedia audio, v...Protokol dan prosedur yang menyediakan layanan komunikasi multimedia audio, v...
Protokol dan prosedur yang menyediakan layanan komunikasi multimedia audio, v...
 
Estetika Humanisme Diskusi Modul Ke-2 Sesi Ke-2.pdf
Estetika Humanisme Diskusi Modul Ke-2 Sesi Ke-2.pdfEstetika Humanisme Diskusi Modul Ke-2 Sesi Ke-2.pdf
Estetika Humanisme Diskusi Modul Ke-2 Sesi Ke-2.pdf
 
Estetika Humanisme Diskusi Modul Ke-1 Pertemuan Ke-2.pdf
Estetika Humanisme Diskusi Modul Ke-1 Pertemuan Ke-2.pdfEstetika Humanisme Diskusi Modul Ke-1 Pertemuan Ke-2.pdf
Estetika Humanisme Diskusi Modul Ke-1 Pertemuan Ke-2.pdf
 
Estetika Humanisme Diskusi Video Sesi Ke-1.pdf
Estetika Humanisme Diskusi Video Sesi Ke-1.pdfEstetika Humanisme Diskusi Video Sesi Ke-1.pdf
Estetika Humanisme Diskusi Video Sesi Ke-1.pdf
 
Jaringan VOIP Ringkasan PTT Pertemuan Ke-1.pdf
Jaringan VOIP Ringkasan PTT Pertemuan Ke-1.pdfJaringan VOIP Ringkasan PTT Pertemuan Ke-1.pdf
Jaringan VOIP Ringkasan PTT Pertemuan Ke-1.pdf
 
PSTN adalah kumpulan jaringan telepon umum yang saling terhubung di seluruh d...
PSTN adalah kumpulan jaringan telepon umum yang saling terhubung di seluruh d...PSTN adalah kumpulan jaringan telepon umum yang saling terhubung di seluruh d...
PSTN adalah kumpulan jaringan telepon umum yang saling terhubung di seluruh d...
 
Pengolahan citra digital adalah teknologi visual yang digunakan untuk mengama...
Pengolahan citra digital adalah teknologi visual yang digunakan untuk mengama...Pengolahan citra digital adalah teknologi visual yang digunakan untuk mengama...
Pengolahan citra digital adalah teknologi visual yang digunakan untuk mengama...
 
Sistem pakar (expert system) adalah sistem yang berusaha mengadopsi pengetahu...
Sistem pakar (expert system) adalah sistem yang berusaha mengadopsi pengetahu...Sistem pakar (expert system) adalah sistem yang berusaha mengadopsi pengetahu...
Sistem pakar (expert system) adalah sistem yang berusaha mengadopsi pengetahu...
 
Estetika Humanisme Ringkasan Pertemuan 1.pdf
Estetika Humanisme Ringkasan Pertemuan 1.pdfEstetika Humanisme Ringkasan Pertemuan 1.pdf
Estetika Humanisme Ringkasan Pertemuan 1.pdf
 
Modul 15 MPTI - Presentasi Hasil Penelitian.docx
Modul 15 MPTI - Presentasi Hasil Penelitian.docxModul 15 MPTI - Presentasi Hasil Penelitian.docx
Modul 15 MPTI - Presentasi Hasil Penelitian.docx
 

Recently uploaded

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 

Recently uploaded (20)

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 

Pertemuan 13 - Shared Preferences and Settings - Word - Salin.pdf

  • 1. Pemrograman Bergerak Shared Preferences and Settings Program Studi : PJJ INFORMATIKA S1 Tatap Muka Kode Matakuliah : 200301315 Disusun oleh : Riad Sahara, S.SI., M.T. 13
  • 2. 2022 2 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id DESKRIPSI MATERI PERTEMUAN 13 Materi Pertemuan 13 Shared Preferences and Settings Deskripsi Materi Shared preferences allow you to store small amounts of primitive data as key/value pairs in a file on the device. To get a handle to a preference file, and to read, write, and manage preference data, use the SharedPreferences class. The Android framework manages the shared preferences file itself. The file is accessible to all the components of your app, but it is not accessible to other apps. Apps often include settings that allow users to modify app features and behaviors. For example, some apps allow the user to set their home location, default units for measurements, and other settings that apply to the entire app. Users don't access settings frequently, because once a user changes a setting, such as a home location, they rarely need to go back and change it again. Sub Capaian Pembelajaran Mata Kuliah (Sub CPMK) Luaran yang diharapkan setelah mengikuti materi pada pertemuan ini - Mahasiswa mampu memahami konsep dan implementasi dari Shared Preferences dan Settings pada aplikasi Android yang akan dikembangkan. Deskrispsi Tugas Tugas dalam bentuk Kuis dengan tipe True/False, nilai maksimal dari Kuis adalah 100 point. Kontrak Perkuliahan Kehadiran Mahasiswa dihitung dengan parameter: 1. View dan Download Modul 2. Mengerjakan Kuis/Tugas 3. Posting/Reply Diskusi/Forum Untuk Komposisi Penilaian: 1. Presensi Kehadiran : 10% 2. Tugas : 40% 3. UTS : 25% 4. UAS : 25%
  • 3. 2022 3 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id Pertemuan 13 Shared Preferences and Settings 13.1.Data Storage Contents • Android File System • Internal Storage • External Storage • SQLite Database • Other Storage Options 13.1.1. Storage Options 13.1.1.1. Storing data ● Shared Preferences—Private primitive data in key-value pairs ● Internal Storage—Private data on device memory ● External Storage—Public data on device or external storage ● SQLite Databases—Structured data in a private database ● Content Providers—Store privately and make available publicly 13.1.1.2. Storing data beyond Android ● Network Connection—On the web with your own server ● Cloud Backup—Back up app and user data in the cloud ● Firebase Realtime Database—Store and sync data with NoSQL cloud database across clients in realtime
  • 4. 2022 4 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id 13.1.2. Files 13.1.2.1. Android File System ● External storage -- Public directories ● Internal storage -- Private directories for just your app Apps can browse the directory structure Structure and operations similar to Linux and java.io 13.1.2.2. Internal storage ● Always available ● Uses device's filesystem ● Only your app can access files, unless explicitly set to be readable or writable ● On app uninstall, system removes all app's files from internal storage 13.1.2.3. External storage ● Not always available, can be removed ● Uses device's file system or physically external storage like SD card ● World-readable, so any app can read ● On uninstall, system does not remove files private to app 13.1.2.4. When to use internal/external storage Internal is best when ● you want to be sure that neither the user nor other apps can access your files External is best for files that ● don't require access restrictions and for ● you want to share with other apps ● you allow the user to access with a computer 13.1.2.5. Save user's file in shared storage ● Save new files that the user acquires through your app to a public directory where other apps can access them and the user can easily copy them from the device
  • 5. 2022 5 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id ● Save external files in public directories 13.1.3. Internal Storage 13.1.3.1. Internal Storage ● Uses private directories just for your app ● App always has permission to read/write ● Permanent storage directory—getFilesDir() ● Temporary storage directory—getCacheDir() 13.1.3.2. Creating a file File file = new File( context.getFilesDir(), filename); Use standard java.io file operators or streams to interact with files 13.1.3.3. External Storage ● On device or SD card ● Set permissions in Android Manifest ○ Write permission includes read permission <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 13.1.3.4. Always check availability of storage public boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; }
  • 6. 2022 6 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id return false; } 13.1.3.5. Example external public directories ● DIRECTORY_ALARMS and DIRECTORY_RINGTONES For audio files to use as alarms and ringtones ● DIRECTORY_DOCUMENTS For documents that have been created by the user ● DIRECTORY_DOWNLOADS For files that have been downloaded by the user 13.1.3.6. Accessing public external directories • Get a path getExternalStoragePublicDirectory() • Create file File path = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES); File file = new File(path, "DemoPicture.jpg"); 13.1.3.7. How much storage left? ● If there is not enough space, throws IOException ● If you know the size of the file, check against space ○ getFreeSpace() ○ getTotalSpace(). ● If you do not know how much space is needed ○ try/catch IOException 13.1.3.8. Delete files no longer needed ● External storage myFile.delete();
  • 7. 2022 7 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id ● Internal storage myContext.deleteFile(fileName); 13.1.3.9. Do not delete the user's files! When the user uninstalls your app, your app's private storage directory and all its contents are deleted Do not use private storage for content that belongs to the user! For example ● Photos captured or edited with your app ● Music the user has purchased with your app 13.1.4. Shared Preferences & SQLite Database 13.1.4.1. SQLite Database ● Ideal for repeating or structured data, such as contacts ● Android provides SQL-like database ● Covered in following chapters and practicals ○ SQLite Primer ○ Introduction to SQLite Databases ○ SQLite Data Storage Practical ○ Searching an SQLite Database Practical 13.1.4.2. Shared Preferences ● Read and write small amounts of primitive data as key/value pairs to a file on the device storage ● Covered in later chapter and practical ○ Shared Preferences 13.1.5. Other Storage Options 13.1.5.1. Use Firebase to store and share data Store and sync data with the Firebase cloud database
  • 8. 2022 8 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id Data is synced across all clients, and remains available when your app goes offline firebase.google.com/docs/database/ 13.1.5.2. Firebase Realtime Database ● Connected apps share data ● Hosted in the cloud ● Data is stored as JSON ● Data is synchronized in realtime to every connected client
  • 9. 2022 9 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id 13.1.5.3. Network Connection ● You can use the network (when it's available) to store and retrieve data on your own web- based services ● Use classes in the following packages ○ java.net.* ○ android.net.* 13.1.5.4. Backing up data ● Auto Backup for 6.0 (API level 23) and higher ● Automatically back up app data to the cloud ● No code required and free ● Customize and configure auto backup for your app ● See Configuring Auto Backup for Apps 13.1.5.5. Backup API for Android 5.1 (API level 22) • Register for Android Backup Service to get a Backup Service Key • Configure Manifest to use Backup Service • Create a backup agent by extending the BackupAgentHelper class • Request backups when data has changed More info and sample code: Using the Backup AP and Data Backup 13.2.Learn more about files ● Saving Files ● getExternalFilesDir() documentation and code samples ● getExternalStoragePublicDirectory() documentation and code samples ● java.io.File class ● Oracle's Java I/O Tutorial
  • 10. 2022 10 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id 13.3.Learn more about backups ● Configuring Auto Backup for Apps ● Using the Backup API ● Data Backup Untuk modul lengkapnya silahkan lihat di modul versi PPT ya
  • 11. 2022 11 Pemrograman Bergerak Universitas Siber Asia Riad Sahara, S.SI., M.T. http://www.unsia.ac.id DAFTAR PUSTAKA [1] Google, D. (2021, 09 24). Dasar-Dasar Developer Android. Retrieved from Google Developers: https://developers.google.com/training/courses/android-fundamentals?hl=id