service 里面使用toast

public class ConnectionService extends Service { private Handler handler = new Handler(); public void restartConnection(){ int sleepTime = reconnectCounter * MIN_RECON_WAIT; if (sleepTime > MAX_RECON_WAIT) { sleepTime = MAX_RECON_WAIT; } String msg = "The connection has been lost. Restart attempt will start in: " + sleepTime/1000 + " seconds"; (new Timer()).schedule( new TimerTask() { public void run() { handler.post(new Runnable() { public void run() { Toast.makeText(getApplicationContext(), "msg", Toast.LENGTH_LONG).show(); reconnectCounter++; this.startConnectionThread() } }); } }, sleepTime); }//end restartConnection }//end ConnectionService

你可能感兴趣的:(timer,String,service,Class)