Android-锁屏功能
当屏幕多久没有点击的时候,进行某种操作就是所谓的锁屏功能。
onCreate:
public void addRunnable() { handler.postDelayed(runnable, Constant.WAIT_TIME); }
监听触摸事件:
@Override public boolean dispatchTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub handler.removeCallbacks(runnable); addRunnable(); return super.dispatchTouchEvent(ev); } Runnable runnable = new Runnable() { @Override public void run() { // TODO Auto-generated method stub // 锁屏的操作 long time2 = System.currentTimeMillis() - time1; LogUtil.i(TAG, "time2= " + time2); doLock(); } };
onDestroy:
handler.removeCallbacks(runnable);