android SystemClock.uptimeMillis()

SystemClock.uptimeMillis()是获取系统从开机启动到现在的时间,期间不包括休眠的时间,这里获得到的时间是一个相对的时间,而不是通过获取当前的时间(绝对时间)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据您提供的代码,可能是因为在Android4.4中没有`getDisplay().getState()`这个方法而导致编译报错。可以尝试使用`getSystemService(Context.WINDOW_SERVICE).getDefaultDisplay().getState()`来获取屏幕状态。请修改代码如下: ``` private void updateShowSeconds() { if (mShowSeconds) { // Wait until we have a display to start trying to show seconds. if (mSecondsHandler == null && getSystemService(Context.WINDOW_SERVICE).getDefaultDisplay() != null) { mSecondsHandler = new Handler(); if (getSystemService(Context.WINDOW_SERVICE).getDefaultDisplay().getState() == Display.STATE_ON) { mSecondsHandler.postAtTime(mSecondTick, SystemClock.uptimeMillis() / 1000 * 1000 + 1000); } IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_ON); mContext.registerReceiver(mScreenReceiver, filter); } } else { if (mSecondsHandler != null) { mContext.unregisterReceiver(mScreenReceiver); mSecondsHandler.removeCallbacks(mSecondTick); mSecondsHandler = null; updateClock(); } } } private final BroadcastReceiver mScreenReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (Intent.ACTION_SCREEN_OFF.equals(action)) { if (mSecondsHandler != null) { mSecondsHandler.removeCallbacks(mSecondTick); } } else if (Intent.ACTION_SCREEN_ON.equals(action)) { if (mSecondsHandler != null) { mSecondsHandler.postAtTime(mSecondTick, SystemClock.uptimeMillis() / 1000 * 1000 + 1000); } } } }; private final Runnable mSecondTick = new Runnable() { @Override public void run() { if (mCalendar != null) { updateClock(); } mSecondsHandler.postAtTime(this, SystemClock.uptimeMillis() / 1000 * 1000 + 1000); } }; ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值