remedy.
remedy.

Reputation: 2022

ORMLite deleteDatabase is not deleting my databases

Upon logout, I'm trying to drop all tables and then re create them when taken back to my LoginActivity.

I tried doing a deleteDatabase but this doesn't seem to be deleting the database at all because when I'm taken back to my LoginActivity, I can still query for the elements inside the database.

I'm trying to drop all tables from within my DrawerActivity when an onClick event is triggered. Here is what I have so far:

DrawerAdapter.java

@Override
    public void onClick(View v) {
        if(getPosition() == 1) {
            context.deleteDatabase("mynew.db");
            context.startActivity(new Intent(context, LoginActivity.class));      //end services here
        }
    }

Since the above is not working, I tried reading up on using the TableUtils to do my table dropping but I'm not sure if I'm supposed to be doing it this way inside my DrawerAdapter. If I am, how do I access those utilities from within the Adapter class? Then what's the next step when trying to recreate the tables that have been dropped?

Upvotes: 0

Views: 157

Answers (1)

GVillani82
GVillani82

Reputation: 17429

Your database will be deleted only if all the active connections are closed. So, ensure that you have no active connections and try again.

You need to call SQLiteDatabase.close() method on your database if you open it without closing it. Each open() requires a close().

Upvotes: 1

Related Questions