文檔 http://developer.android.com/guide/topics/data/data-storage.html保存控件狀態
表明,有多種方式來保存數據,我需要做的這一個部件,每次我試圖挽救我得到的錯誤...
例如
SharedPreferences settings = getSharedPreferences("NAME", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("silentMode", false);
// Commit the edits!
editor.commit();
錯誤
Description Resource Path Location Type
The method getSharedPreferences(String, int) is undefined for the type AWidget
另一嘗試:
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos = openFileOutput("Test.txt", Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
錯誤
Description Resource Path Location Type
The method openFileOutput(String, int) is undefined for the type AWidget
什麼交易?我發現沒有提到這在小部件中不起作用,那麼爲什麼這些示例不適合我?
保存這些數據的首選方法是什麼?
AWidget的基本類型是什麼? – xandy 2010-10-25 03:54:03
正如@ xandy所說的,瞭解您所在班級的類型很重要。 'getSharedPreferences()'在'Context'類中定義。 – 2010-10-25 05:12:15