0
I have a problem with Intentservice, I have an Activity with three spinner they receive the State, City and Neighborhood of a Webservice where the Intentservice performs this task and within onReceive step to the Spinner. When one selects the state automatically the other spinner are filled with the cities and neighborhoods of that state. This works correctly but I need this last user query to be saved in an android sqlite and I put the code in the same Intentservice the question is that it can insert in the sqlite database the states that are in the first spinner only when it will give statService() Again to enter cities the app gives error and closes. Just a detail if I take the command below it works correctly. I do not know why this conflict.
ClasseCriarBanco banco = new ClasseCriarBanco(this, "banc.db", null, 1);
ContentValues valor = new ContentValues();
SQLiteDatabase db = banco.getWritableDatabase();
// banco.close();
//ClasseCriarBanco banco2 = new ClasseCriarBanco(this, "banc.db", null, 1);
SQLiteDatabase dbleitura = banco.getReadableDatabase();
String [] colunas = {banco.ID,banco.ESTADO};
//
Cursor cur = db.query(banco.TABELA,colunas,null,null,null,null,null);
Cursor cur2 = dbleitura.rawQuery("SELECT _id, estado FROM tabela order by estado desc LIMIT 1",null);
if(cur.getCount() > 0){
cur.moveToPosition(i-1);
registroatual = cur.getString(cur.getColumnIndexOrThrow(banco.ESTADO));
cur2.moveToFirst();
ultimoregistro = cur2.getString(cur.getColumnIndexOrThrow(banco.ESTADO));
}else{
registroatual = "primeiroregistro";
ultimoregistro = "primeiroregistro";
}
if (pegaurl.equals("http://listarapido.esy.es/estados") && registroatual.equals(ultimoregistro)){
valor.put(ClasseCriarBanco.ESTADO, finaljs);
db.insert(TABELA,null,valor);
}