How do I start requestLocationUpdates()
with Thread.sleep();
on Android
?
My code:
public void onLocationChanged(Location loc) {
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
SQLiteDatabase db = openOrCreateDatabase("pontos.db", Context.MODE_PRIVATE, null);
db.execSQL("INSERT INTO pontos(latitude, longitude, datahora) VALUES('"+ loc.getLatitude()+"','"+loc.getLongitude()+"','"+ sdf.format(d)+"')");
db.close();
Toast.makeText(getBaseContext(), "Atualizado", Toast.LENGTH_LONG).show();
locationManager.removeUpdates(this);
incremento();
}
private void incremento() {
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new Servico());
}catch(Exception e){}
}
}).start();
}
I call incremento();
at the end of onLocationChanged()
, but nothing happens.
Detail: This is a service in Background.