Which line saves the username in the background without blocking the UI?
- prefs.edit().putString("username", n).commit()
- prefs.edit().putString("username", n)
- prefs.putString("username", n)
- prefs.edit().putString("username", n).apply()
Answer
D) prefs.edit().putString("username", n).apply()
apply() writes asynchronously; without apply/commit nothing is saved.
Computer Science MCQ · More Lab: SharedPreferences MCQs · Practise