File file = new File(mWorkPath);
if (!file.exists()){
boolean b = file.mkdirs();
}
}
public static String getDBpath() {
File file = new File(mWorkPath + DB_PATH_NAME);
if (!file.exists())
file.mkdirs();
return mWorkPath + DB_PATH_NAME;
}
public static void copyAccessDB(Context context) {
try {
String[] dbNames = context.getAssets().list(“db”);
for (String dbName : dbNames) {
long startTime = System.currentTimeMillis();
String filePath = FileUtil.getDBpath() + dbName;
File dbFile = new File(filePath);
if (!dbFile.exists()) {
FileOutputStream fos = null;
try {
dbFile.createNewFile();
}catch (Exception e){
}
InputStream is = context.getAssets().open(“db/” + dbName);
fos = new FileOutputStream(dbFile);
byte[] buffer = new byte[2048];
int len = -1;
while ((len = is.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.close();
long endTime = System.currentTimeMillis();
long useTime = endTime - startTime;
copyTime += useTime;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Android 本地 操作数据库逻辑(查,删,改)
package com.example.testdemo.util;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import com.example.testdemo.bean.User;
import java.util.ArrayList;
import java.util.List;
public class DBManager {
private Context mContext;
private SQLiteDatabase mDB;
private static String dbPath = FileUtil.getDBpath() + “/Test.db”;
private static DBManager instance = null;
public DBManager() {
}
public static DBManager getInstance() {
if (instance == null) {
instance = new DBManager();
}
return instance;
}
/**
- 打开数据库
*/
private void openDB() {
if (isSDCard()) {
if (mDB == null || !mDB.isOpen())
mDB = SQLiteDatabase.openDatabase(dbPath, null,
SQLiteDatabase.OPEN_READWRITE);
}
}
private boolean isSDCard() {
return Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED);
}
//查询选择题
public List queryUser() {
List userList = new ArrayList();
User user= null;
openDB();
try {
String sql = " select a.id,a.name,a.age,a.phoneNum,b.name as sexName from user a,gender b where a.sex= b.type";
Cursor cursor = mDB.rawQuery(sql, null);
while (cursor.moveToNext()) {
String id = cursor.getString(cursor.getColumnIndex(“id”));
String name = cursor.getString(cursor.getColumnIndex(“name”));
String sex = cursor.getString(cursor.getColumnIndex(“sexName”));
String age = cursor.getString(cursor.getColumnIndex(“age”));
String phoneNum = cursor.getString(cursor.getColumnIndex(“phoneNum”));
user= new User();
user.setId(id);
user.setName(name);
user.setAge(age);
user.setPhoneNum(phoneNum);
user.setSex(sex);
userList.add(user);
}
cursor.close();
return userList;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public void updateUser() {
openDB();
String sql = " update user set name = ‘李四’ where name = ‘王杰’ ";
mDB.execSQL(sql);
}
public void deleteUser(String id) {
openDB();
mDB.delete(“user”, " id = ? ", new String[]{id});
}
}
最后:学习总结——Android框架体系架构知识脑图(纯手绘xmind文档)
学完之后,若是想验收效果如何,其实最好的方法就是可自己去总结一下。比如我就会在学习完一个东西之后自己去手绘一份xmind文件的知识梳理大纲脑图,这样也可方便后续的复习,且都是自己的理解,相信随便瞟几眼就能迅速过完整个知识,脑补回来。
下方即为我手绘的Android框架体系架构知识脑图,由于是xmind文件,不好上传,所以小编将其以图片形式导出来传在此处,细节方面不是特别清晰。但可给感兴趣的朋友提供完整的Android框架体系架构知识脑图原件(包括上方的面试解析xmind文档)
除此之外,前文所提及的Alibaba珍藏版 Android框架体系架构 手写文档以及一本 《大话数据结构》 书籍等等相关的学习笔记文档,也皆可分享给认可的朋友!
——感谢大家伙的认可支持,请注意:点赞+点赞+点赞!!!
下方即为我手绘的Android框架体系架构知识脑图,由于是xmind文件,不好上传,所以小编将其以图片形式导出来传在此处,细节方面不是特别清晰。但可给感兴趣的朋友提供完整的Android框架体系架构知识脑图原件(包括上方的面试解析xmind文档)
[外链图片转存中…(img-DgU2E9eH-1725892579837)]
除此之外,前文所提及的Alibaba珍藏版 Android框架体系架构 手写文档以及一本 《大话数据结构》 书籍等等相关的学习笔记文档,也皆可分享给认可的朋友!
——感谢大家伙的认可支持,请注意:点赞+点赞+点赞!!!