TAILIEUCHUNG - Lập trình Androi part 32

Android cho phép các hoạt động và các ứng dụng để giữ cho ưu đãi, theo hình thức chìa khóa / cặp giá trị (giống như một bản đồ), mà sẽ treo khoảng giữa invocations của hoạt động. Như tên cho thấy, mục đích chính là dành cho bạn để lưu trữ thông tin chi tiết cấu hình người dùng chỉ định, chẳng hạn như các nguồn cấp dữ liệu mới nhất cho người sử dụng nhìn vào trong một người đọc nguồn cấp dữ liệu của bạn, thứ tự sắp xếp để sử dụng mặc định trên danh sách,. | Chapter Using Preferences Android has many different ways for you to store data for long-term use by your activity. The simplest to use is the preferences system which is the topic of this chapter. Android allows activities and applications to keep preferences in the form of key value pairs akin to a Map which will hang around between invocations of an activity. As the name suggests the primary purpose is for you to store user-specified configuration details such as the last feed the user looked at in your feed reader the sort order to use by default on a list or whatever. Of course you can store in the preferences whatever you like as long as it is keyed by a String and has a primitive value boolean String etc. Preferences can be for a single activity or shared among all activities in an application. Eventually preferences might be shareable across applications but that is not supported as of the time of this writing. Getting What You Want To get access to the preferences you can use the following APIs getPreferences from within your Activity to access activityspecific preferences getSharedPreferences from within your Activity or other application Context to access application-level preferences getDefaultSharedPreferences on PreferencesManager to get the shared preferences that work in concert with Android s overall preference framework The first two take a security mode parameter for now pass in 0. The getSharedPreferences method also takes a name of a set of preferences. getPreferences effectively calls getSharedPreferences with the activity s class name as the preference set name. The getDefaultSharedPreferences method takes the Context for the preferences . your Activity . 213 CHAPTER 21 Using Preferences All of these methods return an instance of SharedPreferences which offers a series of getters to access named preferences returning a suitably typed result . getBoolean to return a Boolean preference . The getters also take a default value which is .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.