vendredi 20 février 2015

Sequential scheduled tasks___2nd

I'm making an application with Android SRK. I'd try to execute many jobs sequentially with the data from Sqlite database which have been already made. Also, each job should be executed several seconds later after the earlier job has been done. The delay second information is contained in each row of Sqlite DB. More 60 rows of the Sqlite database are expected. Please review my cording and let me have your comments. Thank you.



btnRun.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

db = helper.getReadableDatabase();
final Cursor c = db.query("park", null, null, null, null, null, null);
c.moveToLast();
msg.what = 0;

new Thread(new Runnable() {
@Override
public void run() {

int duration = 0;
int parameter = 0 ;
int commandIndex = 0 ;

while (c.moveToPrevious()) {

String car_kind = c.getString(c.getColumnIndex("command"));
commandIndex = selectionMatch(car_kind);

String car_owner = c.getString(c.getColumnIndex("parameter"));
if (car_owner.equals("")) {
parameter = 0; }
else {
parameter = Integer.parseInt(car_owner); }

String num = c.getString(c.getColumnIndex("duration"));
if (num.equals("")) {
duration = 0; }
else {
duration = Integer.parseInt(num); }

msg.what = commandIndex;
msg.arg1 = parameter;
mainHandler.sendMessage(msg);

try{
Thread.sleep(duration * 1000);
}
catch (InterruptedException e) {;}
}

}
}).start();
}
});

Aucun commentaire:

Enregistrer un commentaire