Hi Guys and Girls,
I'm having some trouble getting a timer to work on my android 2.1 app.
I want it so once a button is clicked it trys to connect to my server
every 60 seconds.
my code for connecting to server is working, but I don't understand why my timer wont.
Timer timer = new Timer();
TimerTask timerConnect = new TimerTask() {
public void run() {
tryconnecting();
if(Globals.socket10400.isConnected())
{
this.cancel();
}
}
};
//this is the method called once button is clicked
private void connectClick()
{
Globals.timer.schedule(timerConnect, 5000, 60000);
}
//working server connect code.
public void tryconnecting()
{
boolean connecting = false;
LblWelcomeMessage.setText("connecting");
while (!connecting)
{
try {
if(Globals.sendTCP.ConnectToServer())
{
LblWelcomeMessage.setText("connected");
connecting = true;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
LblWelcomeMessage.setText("Not Connected");
}
}
}
Thanks in advance.