การจัดการข้อมูล Android
SharedPreferences, DataStore, File I/O, Internal/External Storage, Scoped Storage
1SharedPreferences ใน Android คืออะไร?
SharedPreferences ใน Android คืออะไร?
คำตอบ
SharedPreferences คือระบบจัดเก็บแบบ key-value ที่เรียบง่ายสำหรับบันทึกข้อมูลพื้นฐาน (int, boolean, float, long, String, Set<String>) ข้อมูลจะคงอยู่ระหว่างเซสชันของแอปและการรีบูต เหมาะสำหรับการตั้งค่าผู้ใช้ การตั้งค่า ข้อมูลขนาดเล็ก API ที่เรียบง่าย: getSharedPreferences(), edit(), putString(), apply()/commit()
2จะบันทึกค่าใน SharedPreferences ได้อย่างไร?
จะบันทึกค่าใน SharedPreferences ได้อย่างไร?
คำตอบ
รับ instance: val prefs = context.getSharedPreferences('name', Context.MODE_PRIVATE) แก้ไข: val editor = prefs.edit(); editor.putString('key', 'value'); editor.apply() (async) หรือ editor.commit() (sync) สามารถ chain ได้: prefs.edit().putString('key', 'value').apply()
3ความแตกต่างระหว่าง apply() และ commit() คืออะไร?
ความแตกต่างระหว่าง apply() และ commit() คืออะไร?
คำตอบ
apply() เป็นแบบ asynchronous (เขียนในเบื้องหลัง ไม่บล็อก UI thread) ไม่คืนค่า แนะนำในกรณีส่วนใหญ่ commit() เป็นแบบ synchronous (บล็อกจนกว่าจะเขียนเสร็จ) คืนค่า boolean (true ถ้าสำเร็จ) มีประโยชน์ถ้าต้องตรวจสอบความสำเร็จทันที apply() มีประสิทธิภาพดีกว่าสำหรับ UI
จะอ่านค่าจาก SharedPreferences ได้อย่างไร?
Jetpack DataStore คืออะไร?
+26 คำถามสัมภาษณ์
หัวข้อสัมภาษณ์ Android อื่นๆ
พื้นฐาน Android
UI และทรัพยากร Android
Lifecycle ของ Android
การนำทาง Android
Networking Android
การทดสอบ Android
Android Gradle
พื้นฐานภาษา Kotlin สำหรับ Android
Room Database
การทำงานเบื้องหลัง
Jetpack Compose
สิทธิ์และฟีเจอร์ของอุปกรณ์
Firebase สำหรับ Android
Android MVVM Architecture
เครือข่าย Android ขั้นสูง
Collections และ Operators ใน Kotlin
Kotlin Coroutines และ Flow
การฉีด Dependency ใน Android
Android MVI Architecture
Android Clean Architecture
Android Compose ขั้นสูง
Android Performance and Monitoring
Android Security and Privacy
Android CI/CD and Release
Android UX and Form Factors
Android Testing Advanced
เชี่ยวชาญ Android สำหรับการสัมภาษณ์ครั้งถัดไป
เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์
เริ่มใช้ฟรี