Android-鎖屏功能

當屏幕多久沒有點擊的時候,進行某種操做就是所謂的鎖屏功能。ide

onCreate:post

    public void addRunnable() {
        handler.postDelayed(runnable, Constant.WAIT_TIME);
    }

監聽觸摸事件:spa

    @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:code

        handler.removeCallbacks(runnable);
相關文章
相關標籤/搜索