Android Data Management
SharedPreferences, DataStore, File I/O, Internal/External Storage, Scoped Storage
1What is SharedPreferences in Android?
What is SharedPreferences in Android?
Câu trả lời
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().
2How to save a value in SharedPreferences?
How to save a value in SharedPreferences?
Câu trả lời
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().
3What's the difference between apply() and commit()?
What's the difference between apply() and commit()?
Câu trả lời
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.
How to read a value from SharedPreferences?
What is Jetpack DataStore?
+26 câu hỏi phỏng vấn
Các chủ đề phỏng vấn Android khác
Android Fundamentals
Android UI and Resources
Android Lifecycle
Android Navigation
Android Networking
Android Testing
Android Gradle
Kotlin Language Essentials for Android
Room Database
Background Work
Jetpack Compose
Permissions and Device Features
Firebase for Android
Android MVVM Architecture
Advanced Android Networking
Kotlin Collections and Operators
Kotlin Coroutines and Flow
Android Dependency Injection
Android MVI Architecture
Android Clean Architecture
Android Compose Advanced
Android Performance and Monitoring
Android Security and Privacy
Android CI/CD and Release
Android UX and Form Factors
Android Testing Advanced
Nắm vững Android cho lần phỏng vấn tiếp theo
Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.
Bắt đầu miễn phí