Android getting database disk image is malformed (code 11) error Android getting database disk image is malformed (code 11) error android android

Android getting database disk image is malformed (code 11) error


As I have seen many users have up voted this so I am assuming that a lot of other people are facing the same issue. We were unable to trace back this and now it's not a valid use case in our organization as we have moved away from maintaining a DB in our Android application due to some changes in product roadmap and business logic.I have done some research to find out why it was happening and I have some insights. So if your DB size is very large and you are trying to load it into the memory and you do not have sufficient memory the DB file can get corrupted.One other reason can be that you are maintaining multiple DB connections and trying to access the DB from multiple connections without closing the previous connections properly. Please try to maintain a single connection and use a content provider.The problem with the android system is if DB file is malformed or corrupted due to any reason it won't give you an exception or any other way to handle it manually by yourself. The next time when you are trying to do an operation on the DB and trying to connect to the DB file and when the system detects that the file has been corrupted, Android system recreates a fresh new file and all your data is lost. That's the default behaviour from the android system.So if you are facing this issue in your application also, try to debug for the issue why your DB file is getting corrupted because once your DB file is corrupted you can't do anything to stop this behaviour. One other thing you can do is move to some other DB like Realm. You can explore that as I am not aware of their behaviour as we only experienced this on SQLite DB.