如何清除ActiveAndroid中的所有表?

ip6*_*696 6 android activeandroid

我的ActiveAndroid数据库中有大约20-30个表.当我按下logoutButton我要清除所有表格.我怎么能这样做ActiveAndroid

 public void logOut() {
     //clear all tables
 }
Run Code Online (Sandbox Code Playgroud)

Ily*_*iev 10

        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);
        }
Run Code Online (Sandbox Code Playgroud)


jlo*_*pez 5

试试这个:

 public void logOut() {
     new Delete().from(MyClass.class).executeSingle();
 }
Run Code Online (Sandbox Code Playgroud)