Câu hỏi phỏng vấn Android
Câu hỏi

What is the most appropriate way to store user settings in Android application?

Câu trả lời

The most appropriate way to store user settings in an Android application is to use SharedPreferences[1]. SharedPreferences provide a simple key-value store for storing and retrieving small amounts of primitive data, such as booleans, floats, integers, longs, and strings.

To use SharedPreferences, you first need to get an instance of the SharedPreferences object by calling getSharedPreferences() or getPreferences() methods. Then you can use the SharedPreferences.Editor interface to modify the preferences and commit the changes[1].

For example, to save a user's password using SharedPreferences:

SharedPreferences sharedPref = getSharedPreferences("myPref", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("password", "myPassword");
editor.apply();

And to retrieve the saved password:

String password = sharedPref.getString("password", "defaultPassword");

However, it's important to not...

junior

junior

Gợi ý câu hỏi phỏng vấn

senior

What is the difference between ANR and crash in Android?

junior

What is an Intent in Android?

entry

Mention the difference between RelativeLayout and LinearLayout ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào