androidactiveandroid

How can clear all tables in ActiveAndroid?


I have about 20-30 tables in my ActiveAndroid database. When I press logoutButton I want to clear all the tables. How can I do it in ActiveAndroid?

 public void logOut() {
     //clear all tables
 }

Solution

  •         SQLiteDatabase db = ActiveAndroid.getDatabase();
            List<String> tables = new ArrayList<>();
            Cursor cursor = db.rawQuery("SELECT * FROM sqlite_master WHERE type='table';", null);
            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
                String tableName = cursor.getString(1);
                if (!tableName.equals("android_metadata") &&
                        !tableName.equals("sqlite_sequence")) {
                    tables.add(tableName);
                }
                cursor.moveToNext();
            }
            cursor.close();
            for (String tableName : tables) {
                db.execSQL("DELETE FROM " + tableName);
            }