ADD file via upload

master
pybple5kv 3 years ago
parent ef340ca0e8
commit 673861ba94

@ -0,0 +1,48 @@
package com.example;
import android.app.Application;
import android.database.sqlite.SQLiteDatabase;
import com.example.greendao.DaoMaster;
import com.example.greendao.DaoSession;
public class MyApplication extends Application {
private static DaoSession daoSession;
private static MyApplication instance;
@Override
public void onCreate() {
super.onCreate();
instance = this;
//必须调用初始化
//配置数据库
setupDatabase();
}
public static MyApplication getInstance() {
return instance;
}
/**
*
*/
private void setupDatabase() {
//创建数据库shop.db"
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "shop.db", null);
//获取可写数据库
SQLiteDatabase db = helper.getWritableDatabase();
// 获取数据库对象
DaoMaster daoMaster = new DaoMaster(db);
// 获取Dao对象管理者
daoSession = daoMaster.newSession();
}
public static DaoSession getDaoInstant() {
return daoSession;
}
}
Loading…
Cancel
Save