0
我正在研究Android中的壁纸应用程序,我需要从资产中复制少量图像到SDCARD位置以获取应用程序。但是这个过程必须在第一次应用程序运行时完成。将来用户使用应用程序时不会发生这种情况。 我计划为此使用Shared Preference。但没有获得成功。只有在应用程序首次在Android中运行时才使用共享首选项来调用方法?
我已经将首选项初始化为类的私有成员。
private SharedPreferences preferences=null;
private boolean flagCopy;
//USING Shared Preferences FOR COPY ASSETS------
if(preferences!=null){
flagCopy = preferences.getBoolean("COPY_ASSETS", DO_NOT_COPY_ASSESTS);
}else{
preferences =getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("COPY_ASSETS", COPY_ASSESTS); // value to store
editor.commit();
flagCopy = true;
}
if(flagCopy){//IF FLAG IS FALSE THAN COPY THE IMAGES TO SDCARD FROM RES
CopyAssets();
}
你通过使用这段代码到达那里有什么问题? – Hiral 2012-08-06 05:57:53
我每次运行应用程序时都会收到“首选项”对象为空。 – 2012-08-06 05:59:52