public class ColTimerTaskActivity extends Activity {
/** Called when the activity is first created. */
private final String TAG = "ColTimerTaskActivity";
private final int EVENT_LOCK_WINDOW = 0x100;
private TextView textView;
private Handler mHandler;
private Timer mTimer;
private MyTimerTask mTimerTask;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView)findViewById(R.id.textview);
mHandler = new Handler(){
public void handleMessage(Message message){
Log.i(TAG, "message what = " + message.what);
if (message.what == 0x100){
lockWindow();
}
}
};
mTimer = new Timer(true);
resumeWindow();
StartLockWindowTimer();
}
public boolean onTouchEvent(MotionEvent event)
{
// TODO Auto-generated method stub
resumeWindow();
StartLockWindowTimer();
return super.onTouchEvent(event);
}
public void resumeWindow(){
textView.setText("main window");
}
public void lockWindow(){
textView.setText("lock window");
}
public void StartLockWindowTimer(){
if (mTimer != null){
if (mTimerTask != null){
mTimerTask.cancel(); //将原任务从队列中移除
}
mTimerTask = new MyTimerTask(); // 新建一个任务
mTimer.schedule(mTimerTask, 3000);
}
}
class MyTimerTask extends TimerTask{
@Override
public void run() {
// TODO Auto-generated method stub
Log.i(TAG, "run...");
Message msg = mHandler.obtainMessage(EVENT_LOCK_WINDOW);
msg.sendToTarget();
}
}
}
if (mTimerTask != null){
mTimerTask.cancel(); //将原任务从队列中移除
}
mTimerTask = new MyTimerTask(); // 新建一个任务
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有