I had a app with version 3.2.1 and release version 3.2.2 now. In version 3.2.1 , I had an object with 2 variable for example Name and Email. at First , I Converted The Object to Byte with this code:
public <T> byte[] ObjectToByte(T Object){
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(Object);
byte[] ObjectAsBytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(ObjectAsBytes);
return ObjectAsBytes;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
After that I stored this Object to SQLite by Type Blob. In Version 3.2.2 , I insert a variable to my object. for example Name , Email and Phone. But when I want get object from SQLite with below code , traditional users doesn't have Phone in object ,so my app to crash.
public <T> T ByteToObject(byte[] bytes){
try {
ByteArrayInputStream baip = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(baip);
T dataobj = (T ) ois.readObject();
return dataobj ;
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
and
final mDataBase db = new mDataBase(context);
db.createDB();
Cursor cursor = db.ReadFromDB("select * from "+db.forum_table_v2 + " where " + db.ColType + " = " + "'" + type + "'");
cursor.moveToFirst();
if(cursor.getCount()>0){
while (!cursor.isAfterLast()){
Forum_Item forum_item = new Forum_Item();
forum_item = ByteToObject(cursor.getBlob(cursor.getColumnIndex(db.ColForumItem)));
itemList.add(forum_item);
cursor.moveToNext();
}
}
cursor.close();
db.close();
How can i update old users database and object in database. please attention to : 1 - This object is Serializable 2 - I should update object for one variable. Thank you for attention.