private Long mPeriod = Long.parseLong("8000");public voID startTimer() { Logger.i("startTimer","startTimer"); stopTimer(); mTimer = new Timer(); mTimerTask = new TimerTask() { @OverrIDe public voID run() { // postInvalIDate(); Logger.i("timer","timer"); Thread th = new Thread(new Runnable() { @OverrIDe public voID run() { Logger.i("thread","thread"); Long ll = System.currentTimeMillis(); mrelativeTime = DateUtils.getrelativeTimeSpanString( Long.parseLong(mText + ""),ll,0); Long diff = ll - Long.parseLong(mText + ""); // long diffSeconds = diff / 1000 % 60; long diffMinutes = diff / (60 * 1000) % 60; long diffHours = diff / (60 * 60 * 1000) % 60; Logger.d("diffMinutes",diffMinutes + ""); Logger.d("diffHours",diffHours + ""); if (diffMinutes == 0 && diffHours == 0) { Logger.i("5000","5000"); mPeriod = Long.parseLong("5000"); } else if (diffMinutes < 60 && diffMinutes != 0 && diffHours == 0) { Logger.i("30000","30000"); mPeriod = Long.parseLong("30000"); } else if (diffHours > 0) { Logger.i("600000","600000"); mPeriod = Long.parseLong("600000"); } **// This line is not working... mTimer.scheduleAtFixedrate(mTimerTask,mPeriod);** // Change text handler.sendEmptyMessage(0); } }); th.run(); } }; mTimer.scheduleAtFixedrate(mTimerTask,mPeriod);}public voID stopTimer() { if (mTimer != null) { mTimer.cancel(); mTimer = null; }}解决方法 您必须创建自己的CustomTimerTask类,该类从TimerTask扩展.在此之后,您可以使用mCustomTimerTask(CustomTimerTask的对象)重新安排您的时间. Here是可能重复的答案. 总结
以上是内存溢出为你收集整理的android – 更改计时器计划scheduleAtFixedRate全部内容,希望文章能够帮你解决android – 更改计时器计划scheduleAtFixedRate所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)