Android

Android Data Management

SharedPreferences, DataStore, File I/O, Internal/External Storage, Scoped Storage

29 คำถามสัมภาษณ์·
Junior
1

What is SharedPreferences in Android?

คำตอบ

SharedPreferences is a simple key-value storage system for saving primitive data (int, boolean, float, long, String, Set<String>). Data persists between app sessions and reboots. It's ideal for user preferences, settings, small data. Simple API: getSharedPreferences(), edit(), putString(), apply()/commit().

2

How to save a value in SharedPreferences?

คำตอบ

Get instance: val prefs = context.getSharedPreferences('name', Context.MODE_PRIVATE). Edit: val editor = prefs.edit(); editor.putString('key', 'value'); editor.apply() (async) or editor.commit() (sync). Can also chain: prefs.edit().putString('key', 'value').apply().

3

What's the difference between apply() and commit()?

คำตอบ

apply() is asynchronous (writes in background, doesn't block UI thread), returns nothing, recommended in most cases. commit() is synchronous (blocks until written), returns boolean (true if success), useful if you need to verify success immediately. apply() is more performant for UI.

4

How to read a value from SharedPreferences?

5

What is Jetpack DataStore?

+26 คำถามสัมภาษณ์

เชี่ยวชาญ Android สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี