public static void saveObj(Context context, SharedPreferences sp,
String key, Object value) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(
byteArrayOutputStream);
objectOutputStream.writeObject(value);
String objString = new String(Base64.encode(
byteArrayOutputStream.toByteArray(), Base64.DEFAULT));
sp.edit().putString(key, objString).commit();
objectOutputStream.close();
}
public static Object getObj(Context context, SharedPreferences sp,
String key) throws StreamCorruptedException, IOException,ClassNotFoundException {
String str = sp.getString(key, "");
if (str.length() <= 0)
return null;
Object obj = null;
byte[] mobileBytes = Base64.decode(str.toString().getBytes(),
Base64.DEFAULT);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
mobileBytes);
ObjectInputStream objectInputStream;
objectInputStream = new ObjectInputStream(byteArrayInputStream);
obj = objectInputStream.readObject();
objectInputStream.close();
return obj;
}