惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
IT之家
IT之家
Y
Y Combinator Blog
T
Tailwind CSS Blog
B
Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
InfoQ
J
Java Code Geeks
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog

博客园 - MSTK

PCB检测算法YOLO-EMAC(2) PCB检测算法YOLO-EMAC(1) Android Studio提高Build速度 Android创建LiteOrmManager类(4) DecoView的使用 Android创建LiteOrmManager类(3) Android创建LiteOrmManager类(2) Android创建LiteOrmManager类(1) Android使用Snackbar Unable to add window -- token null is not valid; is your activity running? Android Studio集成通义灵码 MonoDETR(2) MonoDETR(1) The color "XXX" in values has no declaration in the base values folder; this can lead to crashes when the resource is queried in a configuration that does not match this qualifier LiteORM的使用(2) 使用AlarmManager实现APP保活(2) 使用AlarmManager实现APP保活(1) CEC2017的30个函数 使用双进程实现Android APP保活 Process finished with exit code 137 (interrupted by signal 9: SIGKILL) GIT RE-BASIN: MERGING MODELS MODULO PERMUTATION SYMMETRIES (1) MMpretrain使用Tiny ImageNet数据集 Ubuntu使用dd命令实现硬盘级复制 PyCharm debug collecting data...
LiteORM的使用(1)
MSTK · 2025-05-29 · via 博客园 - MSTK

SQLite是一种轻量级数据库,经常在Android开发中使用.LiteOrm是一个专为 Android 设计的轻量级、高性能的ORM(对象关系映射)框架,通过该框架可以通过简洁的代码对SQLite数据库进行增删查改等操作.Android开发中使用LiteOrm的步骤如下:

(1)下载lite-orm-1.9.2.jar文件,并放入Android项目的jniLibs目录;

(2)在项目中定义LiteOrm_Manager类:

public class LiteOrm_Manager {
    private static volatile LiteOrm_Manager s_instance;
    private static LiteOrm lite_orm;
    public LiteOrm_Manager(Context context) {
        if (lite_orm == null) {
            DataBaseConfig config = new DataBaseConfig(context, XXXApplication.database_name);
            config.debugged = XXXApplication.is_debug_orm;
            config.dbVersion = XXXApplication.db_version;
            lite_orm = LiteOrm.newSingleInstance(config);
            LiteOrm lite_orm = LiteOrm.newCascadeInstance(context, XXXApplication.database_name);
        }
    }

    public static LiteOrm_Manager get_instance(Context context) {
        if (null == s_instance) {
            synchronized (LiteOrm_Manager.class) {
                if (null == s_instance) {
                    s_instance = new LiteOrm_Manager(context);
                }
            }
        }
        return s_instance;
    }
    ...
}

通过以上代码,获得一个数据库的实例;

(3)在Application或者MainActivity类中定义下列的方法并调用,获得LiteOrm_Manager类的实例:

    private void init_application(){
        if (lite_orm_manager == null) {
            lite_orm_manager = new LiteOrm_Manager(getApplicationContext());
        }
    }