I have an application where the purpose is to put the name of a stop and after reboot to the android device get the name of that stop in reboot receiver
My boot receiver is working because I already tested it only gives error when I try to access data from my sqlite database where the error is NullPointerException;
Code where I create my sqlite database BDcore.java:
public class BDCore extends SQLiteOpenHelper {
private static final String NOME_BD = "teste";
private static final int VERSAO_BD = 6;
public BDCore(Context ctx){
super(ctx,NOME_BD , null , VERSAO_BD);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table favoritos(_id integer primary key autoincrement , favid intenger not null , linha text not null, paragem text not null, horas text not null);");
db.execSQL("create table utilizador(_id2 integer primary key autoincrement, utilizadorId integer not null);");
db.execSQL("create table ultutilizador(_id3 integer primary key autoincrement , ultid intenger not null);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table favoritos");
db.execSQL("drop table utilizador");
db.execSQL("drop table ultutilizador");
onCreate(db);
}
}
I put the data in my sqlite database through my user login activity:
SQLiteDatabase db;
BDCore auxBd = new BDCore (this);
db = auxBd.getWritableDatabase();
ContentValues valores = new ContentValues();
valores.put("favid", 3);
valores.put("linha", "teste");
valores.put("paragem", "PARAGEMTESTE");
valores.put("horas", "teste");
db.insert("favoritos", null, valores);
My boot receiver:
public class BootReceiver extends BroadcastReceiver {
SQLiteDatabase db;
String paragem;
@Override
public void onReceive(Context context, Intent intent) {
String[] colunas = new String[]{"_id", "favid", "linha", "paragem" , "horas" };
Cursor cursor2 = db.query("favoritos", colunas, null, null, null, null, null);
HorariosActivity.context = context;
if (cursor2.getCount() > 0) {
cursor2.moveToFirst();
do {
paragem = cursor2.getString(3);
}
while ( cursor2.moveToNext());
}
}
}