• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to clear database?

vovs

Newbie
Hi, All..
I have ChatApp.
All message save in local database.

When user press button "Log out" i need clear data about chats and contacts from DB.
I am clearing my shared_prefs(Log Out) and call clearMethod():
Code:
public void onClear(SQLiteDatabase db) {
        db.execSQL("DROP TABLE IF EXISTS " + Contact.TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + ChatSessions.TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + ChatSessions.FK_TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + Message.TABLE_NAME);
        onCreate(db);
    }
When i try login - i see all my previous chats(DB si CLEAR).

When i call Settings > Manage Applications> Menu button > Filter by Running. > Select Myapplication > Force stop
and try login - all OK - chatlist is clear!

How to correct clear database?
Calling Force stop - is very hard way ((
 
2SoftWyer

Can't you just "DELETE FROM TABLE xxxx" ?

If I run these command tables will be cleared. But App still running and I can view all data from DB in my app(chatlists, all contacts etc.. )...
Only when I do "Force stop" and try run - then my app will be use clear DB.

Another option is to delete the whole database: context.deleteDatabase(DATABASE_NAME);

In these case my app is down, but in Settings > Manage Applications> Menu button > Filter by Running. > Select Myapplication
button "Force stop" is active.....

Does it possible to clear db and reinitialize my app to view clear lists(chat, contacts etc)?
 
I'm not sure what the problem is. When you say you can still see it, do you mean from within the application using "SELECT"? Or externally from a database viewer?

If you "DELETE FROM TABLE xxx" and commit, then it should be gone. If you can still do a "SELECT" and see the data, then either you didn't delete the right data or you didn't commit and it rolled back.

In my application I call the deleteDatabase(name) command and it physically deletes the database, I just then create a new one.

When I tried to use DROP, it didn't seem to do anything, at least it didn't free up any physical space. Try DELETE and not DROP
 
hi, i just want to know if you're asking how to delete the whole database or a single form? because it's so easy to clear the whole database even without asking, you just need to learn it from yourself.

more exciting games here : Games | Fun Games
 
Why don't you turn your code the initially reads the database, and populates the program into a method. Then call that method after you have cleared out the databases. Sounds like you are clearing the databases, but not reloading the data into the program (even blank data).
 
Back
Top Bottom