How to set a Timer, say for 2 minutes, to try to connect to a Database then throw exception if there is any issue in connection?
How to set a Timer, say for 2 minutes, to try to connect to a Database then throw exception if there is any issue in connection?
[Android] if someone looking to implement timer on android using java.
you need use UI thread like this to perform operations.
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
ActivityName.this.runOnUiThread(new Runnable(){
@Override
public void run() {
// do something
}
});
}
}, 2000));