2011-04-18 121 views
0

您好我正在開發android應用程序。如何將數據存儲在臨時內存中

我想要的方式或代碼,例如將編輯文本框的值存儲在臨時變量中,所以當我重定向活動時,它將值存儲在臨時變量中。當我回到活動時,我可以將其存儲回編輯文本框。

所以請幫助我,如果你知道任何方式。

回答

0

你可以使用SharedPreferences。

import android.content.SharedPreferences; 

... 

private SharedPreferences mPrefs; 

private static final String MY_TEXT_BOX_STRING_KEY = "prefs_textbox_key" 

... 

mPrefs = getSharedPreferences("myAppPrefs",0); 

... 

// Get the string: 

myTextBoxString = prefsGetString(MY_TEXT_BOX_STRING_KEY); 

// Set the string: 

prefsSetString(MY_TEXT_BOX_STRING_KEY, "blahblah");