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);

 

转载于:https://www.cnblogs.com/gongcb/p/4381482.html

你可能感兴趣的:(Android-锁屏功能)