今天正式把SQLlite丢进模拟机试看看

public class DatabaseActivity extends AppCompatActivity implements View.OnClickListener {

private TextView textView;
private String mDatabaseName;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_database);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
textView = findViewById(R.id.tv_result);
findViewById(R.id.btn_create).setOnClickListener(this);
findViewById(R.id.btn_delete).setOnClickListener(this);
mDatabaseName = getFilesDir()+"/test.db";
}

@Override
public void onClick(View view) {
String desc = null;
if(view.getId()==R.id.btn_create){
SQLiteDatabase db = openOrCreateDatabase(mDatabaseName, Context.MODE_PRIVATE, null);
desc = String.format("数据库%s创建%s",db.getPath(),(db!=null)?"成功":"失败");
textView.setText(desc);
}else {
boolean result = deleteDatabase(mDatabaseName);
desc = String.format("数据库%s删除%s",mDatabaseName,result?"成功":"失败");
textView.setText(desc);
}
}
}

建立资料库跟删除:)