正在加载图片...
public class Example extends Activity /Create a preference file with the name specified public static final String PREFS_NAME "MyPrefsFile"; @Override protected void onCreate(Bundle state){ super.onCreate(state); /Restore the preferences //Get the preference with the name specified SharedPreferences settings getsharedPreferences(PREFS_NAME,0); /Read the stored data from the preference int data settings.getInt("key",defaultvalue); com.example.toml.sharedpreference 2015-09-0212:12dw0-x-x cache 2015-09-02 11:23 drwxrwx--x @Override 三ib 2015-09-0211:23 Irwxnwxrwx >/data/a... protected void onStop(){ 2015-09-02 1212 drwxrwx--x 目Filel.xml 1092015-09-0212:12 super.onstop(); -nw-n---- /Store the preferences /We need an Editor object to make preference changes. SharedPreferences settings getsharedPreferences(PREFS_NAME,0); SharedPreferences.Editor editor settings.edit(); editor.putInt("key",value); //Commit the edits! editor.commit(); 88 public class Example extends Activity { // Create a preference file with the name specified public static final String PREFS_NAME = "MyPrefsFile"; @Override protected void onCreate(Bundle state){ super.onCreate(state); . . . // Restore the preferences // Get the preference with the name specified SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); // Read the stored data from the preference int data = settings.getInt(“key", defaultValue); . . . } @Override protected void onStop(){ super.onStop(); // Store the preferences // We need an Editor object to make preference changes. SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putInt(“key”, value); // Commit the edits! editor.commit(); } }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有