大佬教程收集整理的这篇文章主要介绍了从服务开始的Android Toast只显示一次,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
日志条目
public class Connectionservice extends service { ..... public void restartConnection() { try { Log.i(this.toString(),"AttempTing to reconnect..."); // increase the wait between each retry until the max is reached 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"; Log.i(this.toString(),msg); Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_LONG).show(); Thread.sleep(sleepTimE); // increment the counter reconnectCounter++; this.startConnectionThread(); } catch (Exception E) { Log.e(this.toString(),"Exception: " + e.toString()); e.printStackTrace(); } }// end retartConnection
这是我头上的一些代码.我现在没有SDK来测试它,但我认为它应该给你一个一般的想法.
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
以上是大佬教程为你收集整理的从服务开始的Android Toast只显示一次全部内容,希望文章能够帮你解决从服务开始的Android Toast只显示一次所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。