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:

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

And to retrieve the saved password:

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

However, it's important to not...

junior

junior

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

expert

What happens if the user navigates away or closes the app while I still have a reference to the Activity
the user just closed in my AsyncTask ?

expert

What is the onTrimMemory method?

junior

Explain the build process in Android

Bình luận

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

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