SharedPreferences:
Interface for accessing and modifying preference data returned by getSharedPreferences(String, int)
. For any particular set of preferences, there is a single instance of this class that all clients share. Modifications to the preferences must go through an SharedPreferences.Editor
object to ensure the preference values remain in a consistent state and control when they are committed to storage.
可以用来在共享数据。
在SharedPreferences中保存数据,当Acitivity再次被launch,调用onResume()时,读取之前保存的数据。
注意:
1) SharedPreferences.Editor 用于编辑共享的数据
2)EditText 中的getSelectionStart()和getSelectionEnd()
代码如下:
PresistentState.java
main.xml