합쭈기 programming

SharedPreferences 본문

Java/Android

SharedPreferences

innocent_k 2015. 4. 13. 10:40
public class Repository {
	
	private static Repository repository;
	private SharedPreferences sharedPreferences;

	public static Repository getInstance(Context context) {
		if(repository == null) repository = new Repository(context);
		else if(repository.isNullSharedPreferences()) repository = new Repository(context);

		return repository;
	}
	
	public void setNotifyCnt(int cnt) {
		sharedPreferences.edit().putInt("cnt", cnt).commit();
	}

	public int getNotifyCnt() {
		return sharedPreferences.getInt("cnt", 0);
	}

	public void setServerUrl(String url) {
		sharedPreferences.edit().putString("url", url).commit();
	}

	public String getServerUrl() {
		return sharedPreferences.getString("url", "");
	}
	
	private Repository(Context context) {
		sharedPreferences = context.getApplicationContext().getSharedPreferences(getClass().getPackage().getName(), Context.MODE_PRIVATE);
	}
}

'Java > Android' 카테고리의 다른 글

sqlite 기본  (0) 2015.04.13
스크롤 안에 리스트  (0) 2015.04.13
http connect - json  (0) 2015.04.13
http connect - 파일 업로드  (0) 2015.04.13
hidden keyboard  (0) 2015.04.13