private SQLiteDatabase m_dbSQLiteDatabase=null;
private TextView m_textview1=null;
private static final int INFORMATIONACT=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(MainActivity.this,yypService.class);
startService(intent);
m_textview1=(TextView)findViewById(R.id.textview1);
//创建或打开数据库
Button button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener(){
public void onClick(View v){
m_dbSQLiteDatabase=OpenOrCreateDB();
if(m_dbSQLiteDatabase==null)
m_textview1.setText("数据库打开失败!");
else
m_textview1.setText("数据库打开成功!");
}
private SQLiteDatabase OpenOrCreateDB() {
SQLiteDatabase dbSQLiteDatabase=null;
try{
dbSQLiteDatabase=SQLiteDatabase.openOrCreateDatabase("/data/data/com.example.demo_01/xiao.db",null);
//以读写方式打开数据库
}
catch(Exception ex){
return null;
}
return dbSQLiteDatabase;
}
});
yanrun