There is a problem deleting the SQLite file from my application. I am using code like this:
file file = new file ("data / data /" + context.getPackageName () + "/ database / *****"); D = file.delete (); Dbidaptor DBA = new DABAdapter (reference); Dba.open (); Dba.close ();
Earlier, I was using the method context.deleteDatabase (DATABASE_NAME)
to do this. The problem is: After running this method, this application does not refresh, I have an old database and I am able to delete, insert and etc. On both cases, I must restart my application to see the new database.
Occasionally, after running the system, when I try to access some of the methods of the database, the app crashes with error that I do not have a database and After the restart, the new database has been created.
What do I do?
Edit I have a large system. My database has 26 tables and lots of constringes are easy to delete and recreate the database.
EDIT2
DB adapter dba = new DB adapter (reference); SQLiteDatabase sqlite = dba.open (); Dba.close (); Boolean D = context Delete Database ("Carramabdi"); Dba.open (); Dba.close ();
I've closed the DB.
Why not instead you can leave the tables in your DB and make them again Which is more practical than removing a file.
And to store your old values for your ideas, you can refresh the entire activity by calling this code
public refresher_me () {intention intent = GetIntent (); End(); StartActivity; } Edit: Just one thought passed my mind about the creation of new DB, a DB file will be created on the creation of your app, you will get a copy of that file. Such as DB2, and when you remove DB instead of trying to create a new one, DB2 is copied as DB and with each extinction process And for copy - here is the code by @Rakshi
throws a copy of the public void (file src, file DST) IOException {InputStream = new FileInputStream (src); OutputStream Out = New FileOutputStream (DST); // Byte-byte transfer byte [] buf = new byte [1024]; Int len; While ((lane = r) buf) gt; 0) {out.write (buf, 0, len); } In.close (); Out.close (); }
Comments
Post a Comment