正在加载图片...
public class Example extends Activity t Create a preference file with the name specified public static final String PREFS NAME "MyPrefs file"i @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)j / Read the stored data from the preference int data ttings getInt(key", defaultvalue; protected void onStop(t super. onstop o; // Store the preferences // We need an Editor object to make preference changes SharedPreferences settings= getsharedPreferences(PreFs NAME, 0) SharedPreferences Editor editor settings edito editor. putInt ("key,, value); // Commit the edits! editor. commit 1717 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 高等教育资讯网 版权所有