1 开启就启动服务
接受开机广播,使得即使没有点开应用,也让程序的Service在后台运行
</pre><pre name="code" class="html"><pre name="code" class="java">public class GocReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Log.d("GocReceiver", "get action "+intent.getAction());
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
startServices(context);
}
else if(intent.getAction().equals("com.goodocom.gocsdk.INIT_SUCCEED")){
startServices(context);
}
}
private void startServices(Context context){
if(Config.JAVA_SDK)context.startService(new Intent(context,GocsdkService.class));
if(Config.JAVA_PLAYER)context.startService(new Intent(context,PlayerService.class));
if(Config.JAVA_SCO)context.startService(new Intent(context,ScoService.class));
}
}
</pre>
2 MainActivity
onCreate():
1.创建数据库
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(mDbPath, null);
db.execSQL(name);//创建表,表面为name
<span>// SQLiteDatabase类是android上对sqlite的最底层的封装,几乎所有的对数据库的操作最终都通过这个类来实现。
</span>//SQLiteOpenHelper.java类是方便操作数据库的类。其实它的getWritableDatabase方法里最终也是调用了 (书上是介绍的用这个类创建数据库)<pre name="cod