SharedPreferences in Android SDK is a lightweight, key-value pair storage mechanism. It allows developers to store small amounts of data in the form of primitive types such as boolean, float, int, long, and String. It's commonly used for saving user preferences or application settings.
SharedPreferences provides a simple API to fetch and update data. It is persistent, meaning the data will remain across sessions. This makes it ideal for storing user preferences, app settings, or other small bits of information that need to be preserved.
Here is a simple example of how to use SharedPreferences in Android:
// Save data to SharedPreferences
SharedPreferences sharedPreferences = getSharedPreferences("MyPreferences", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("username", "JohnDoe");
editor.putBoolean("isLoggedIn", true);
editor.apply(); // or editor.commit();
// Retrieve data from SharedPreferences
String username = sharedPreferences.getString("username", "defaultUser");
boolean isLoggedIn = sharedPreferences.getBoolean("isLoggedIn", false);
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?