SharedPreferences prefs = getSharedPreferences("MyPrefs", MODE_PRIVATE); boolean isUserLoggedIn = prefs.getBoolean("isLoggedIn", false);
SharedPreferences.Editor editor = getSharedPreferences("MyPrefs", MODE_PRIVATE).edit(); editor.putBoolean("isLoggedIn", true); editor.apply();This code creates an Editor object, stores a boolean value with the key "isLoggedIn" and value true in a SharedPreferences object named "MyPrefs". The apply() method is used to commit the changes asynchronously. Overall, android.content.SharedPreferences is a useful package library for storing user preferences and other simple data in an Android application.