领透酷医云安卓客户端

AppSharePreference.java 987B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.linkdialy.mobile.kuyicloud.sp;
  2. import android.content.Context;
  3. import android.content.SharedPreferences;
  4. /**
  5. * 保存用户信息
  6. * Created by Administrator on 2015-07-09.
  7. */
  8. public class AppSharePreference {
  9. private SharedPreferences sp;
  10. private SharedPreferences.Editor editor;
  11. public String spName = "AppSharePreference";
  12. public AppSharePreference(Context context) {
  13. sp = context.getSharedPreferences(spName, Context.MODE_PRIVATE);
  14. editor = sp.edit();
  15. }
  16. /**
  17. * 保存cookie
  18. *
  19. */
  20. public AppSharePreference putCookie(String cookie) {
  21. editor.putString("cookie", cookie);
  22. return this;
  23. }
  24. /**
  25. * 获取保存的cookie
  26. *
  27. */
  28. public String getCookie() {
  29. return sp.getString("cookie", "");
  30. }
  31. /**
  32. * 最终提交修改的方法,对保存操作,必须在最后调用此方法
  33. */
  34. public void apply() {
  35. editor.apply();
  36. }
  37. }