1
SharedPreferences의 파일을 대체 한 후 새 SharedPreferences 파일을로드 할 수 없습니다. 응용 프로그램을 다시 설치 한 후에 작동합니다. 응용 프로그램을 다시 시작한 후에는 아무 것도 변경되지 않습니다. SharedPreferences를 가져올 수 없습니다.
이
가져 오기/내보내기 클래스입니다 :public class Prefs {
private String PrefsDir = "/data/%packagename%/shared_prefs/";
private String ExportDir = "/";
private SharedPreferences _sharedPrefs;
private SharedPreferences.Editor _prefsEditor;
private Context context;
Prefs(Context context, String form) {
this.ExportDir = Environment.getExternalStorageDirectory().getPath() + ExportDir;
this.PrefsDir = Environment.getDataDirectory().getPath() + PrefsDir;
_sharedPrefs = context.getSharedPreferences(form, Activity.MODE_PRIVATE);
_prefsEditor = _sharedPrefs.edit();
}
private boolean copyfile(String srFile, String dtFile){
Popup.log("srFile = "+srFile);
Popup.log("dtFile = "+dtFile);
try{
File f1 = new File(srFile);
File f2 = new File(dtFile);
InputStream in = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
} catch(FileNotFoundException ex) {
Popup.popup(context, "File not found");
Popup.log(ex.getMessage());
return false;
} catch(IOException e) {
Popup.popup(context, "IO Error");
return false;
}
return true;
}
boolean Export(String form) {
return copyfile(PrefsDir+form+".xml", ExportDir+form+".xml");
}
boolean Import(String form) {
return copyfile(ExportDir+form+".xml", PrefsDir+form+".xml");
}
}
내가 미안 해요 내 영어 내 구현의 첫 번째 부분은 공유 환경 설정을 검색하는 데 사용되는 키를 정의의 선언으로 구성