Hello everyone, I have an application that works with a database, I want to execute a query in the base like the one I leave later, the detail is that this method (query) should only be executed at 7:30 in the morning every days can someone help me with this problem.
In advance thanks for the help
public void borrarRegistros(){
String consulta="delete from registros"; //borrar todos los registros de la tabla registros
MainActivity.adapter.openSqliteDataBaseInDevice();
try {
Cursor c=MainActivity.adapter.get_sqliteDB().rawQuery(consulta,null);
c.moveToFirst();
c.close();
}catch (Exception ex){
}
MainActivity.adapter.closeSqliteDataBaseInDevice();
}
the ideal for your case is neither of the two, at least not the service directly. You need to use the AlarmManager , which makes sure to "wake up" your app, even if it's not running, and via an intent , trigger the action or query you need! More info here " Recurring alarms ". The alarm service can wake up a service and do the query in the background.
Usage example: