//Get the Date corresponding to 11:01:00 pm today.
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUROFDAY, 23);
calendar.set(Calendar.MINUTE, 1);
calendar.set(Calendar.SECOND, 0);
Date time = calendar.getTime();
timer = new Timer();
timer.schedule(new RemindTask(), time);
每一个Timer仅对应唯一一个线程。
Timer不保证任务执行的十分精确。
Timer类的线程安全的。
参考
void cancel()
Cancels the Timer and all scheduled tasks.
int
purge()
Removes all canceled tasks from the task queue.
void
schedule(TimerTask task, Date when, long period)
Schedule a task for repeated fixed-delay execution after a specific time has been reached.
直到when设定的时间开始,间隔period时间执行一次task,间隔时间是从task完成之后开始计时
void
schedule(TimerTask task, long delay, long period)
Schedule a task for repeated fixed-delay execution after a specific delay.
等待delay时间,每间隔period时间执行task
void schedule(TimerTask task, Date when)
Schedule a task for single execution.
直到when执行一次task
void schedule(TimerTask task, long delay)
Schedule a task for single execution after a specified delay.
等待delay时间执行一次task
void scheduleAtFixedRate(TimerTask task, long delay, long period)
Schedule a task for repeated fixed-rate execution after a specific delay has passed.
等待delay设定时间,间隔period时间执行一次task,间隔时间是从task开始之后计时,可能task完成需要的时间超过period的时间,则有可能同时有多个task在执行。
void scheduleAtFixedRate(TimerTask task, Date when, long period)
Schedule a task for repeated fixed-rate execution after a specific time has been reached.
直到when设定的时间开始,间隔period时间执行一次task,间隔时间是从task开始之后计时
public class TimeThread extends Thread {
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case 1:
long sysTime = System.currentTimeMillis();
CharSequence sysTimeStr = DateFormat.format("hh:mm:ss", sysTime);
tv.setText(sysTimeStr);
break;
default:
break;
}
}
};
@Override
public void run() {
do {
try {
Thread.sleep(1000);
Message msg = new Message();
msg.what = 1;
handler.sendMessage(msg);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (true);
}
}
getApplicationContext() Application context is associated with the Application and will always be the same throughout the life cycle.
这个函数返回的这个Application的上下文,所以是与app挂钩的,所以在整个生命周期里面都是不变的
getBasecontext() should not be used just use Context instead of it which is associated with the activity and could possible be destroyed when the activity is destroyed.
stackoverflow上面写的是,这个函数不应该被使用,用Context代替,而Context是与activity相关连,所以当activity死亡后可能会被destroyed
getApplication() is available to Activity and Services only. Although in current Android Activity and Service implementations, getApplication() and getApplicationContext() return the same object, there is no guarantee that this will always be the case (for example, in a specific vendor implementation). So if you want the Application class you registered in the Manifest, you should never call getApplicationContext() and cast it to your application, because it may not be the application instance (which you obviously experienced with the test framework).
getApplication只能被Activity和Services使用,虽然在现在的android的实现中,getApplication和getApplicationContext返回一样的对象,但也不能保证这两个函数一样(例如在特殊的提供者来说),所以如果你想得到你在Manifest文件里面注册的App class,你不要去调用getApplicationContext,以为你可能得不到你所要的app实例(你显然有测试框架的经验)。。。。
getParent() returns object of the activity if the current view is a child..In other words returns the activity object hosting the child view when called within the child.
返回activity的上下文,如果这个子视图的话,换句话说,就是当在子视图里面调用的话就返回一个带有子视图的activity对象
Windows Live Writer 安装遇到问题与解决办法: 现在很多Blog网站都提供后台操作平台,但是对于很多经常在Blog上面写文章的同仁来说,这确实不是个明智之举,一个是Blog后台的编辑能力比较弱,不适合写长篇文章;再一个原因是不能离线操作,写起来不方便。介于以上两点,很多同仁都选择Windown Live Writer 来做了写作的首选工具,具体操作方法笔者就不在这里的介绍了,电脑玩物有一篇文章介绍的很好【如何用Windows Live Writer寫Blog】,是一篇非常好的入门教材,如果有兴趣可以看看,而且里面还有很多相关的文章可以学习。现在Writer已经升级到2011了,界面做的非常干净漂亮,而且功能也非常好。 由于众所周知的原因,在国内很多国外的Blog平台都不能使用,比如笔者现在用的Blogger,平台无法登陆,那Writer也在无从谈起,下面我将介绍一下在国内如果用Writer链接Blogger. 首先下载【Windows Live Essentials】,(微软的软件包,Vista W7),然后运行该程序,选择Windows Live Writer 安装,安装好之后可以看到下面的图片。