有谁知道如何在greenDAO中做一个简单的select * from table并将其放入实体中?我对此进行了一些研究,但我无法得到任何简单的例子。这是我到目前为止所拥有的:

public void storeAppTimeUsageData(AppTimeUsage stats) {
    List<AppTimeUsage> items = new ArrayList<>();
    //appTimeUsageDao = DeviceInsightApp.getSession(this, true).getAppTimeUsageDao();
    try {
        // master
        appTimeUsageDao.insertOrReplace(stats);
    //} catch (IOException e) {
    } catch (Exception e) {
        Log.e("Error", "Some exception occurred", e);
        Log.e("APP_TAG", "STACKTRACE");
        Log.e("APP_TAG", Log.getStackTraceString(e));
    }
    String sql = "SELECT * FROM APP_TIME_USAGE ";
    Cursor c = appTimeUsageDao.getDatabase().rawQuery(sql, null);
    int offset = 0;
    int d ;
    int cd ;
    String e = "";
    while (c.moveToNext()) {
        AppTimeUsage atu AppTimeUsage(
            c.getLong(0);
            //long b =   c.getInt(0);
            d = c.getInt(2);
            e = c.getString(3);
            break;
        );
        items.add(atu);
    }
}

最佳答案

GreenDAO已经带有用于完成此任务的内置方法。在您的情况下:

List<AppTimeUsage> items = appTimeUsageDao.loadAll();

这将从APP_TIME_USAGE中选择所有记录,并返回包含实体的List<AppTimeUsage>

08-03 13:05