public void long getDeltaTime()
{
    if (mLastTime == 0L)
    {
        mLastTime = System.currentTimeMillis();
    }    long t = System.currentTimeMillis();
    mDeltaTime = t - mLastTime;
    mLastTime = t;
    return mDeltaTime;
}求距离上次调用这个函数经过的时间.
mLastTime, mLastTime都是long型变量奇怪的是,偶尔mDeltaTime得到的是负的, 谁知道为什么

解决方案 »

  1.   

    public static long currentTimeMillis ()Added in API level 1
    Returns the current time in milliseconds since January 1, 1970 00:00:00.0 UTC.This method always returns UTC times, regardless of the system's time zone. This is often called "Unix time" or "epoch time". Use a DateFormat instance to format this time for display to a human.This method shouldn't be used for measuring timeouts or other elapsed time measurements, as changing the system time can affect the results. Use nanoTime() for that.看一下 组后那段,这个方法不要用于测试超时或者 经过实践,如果更改系统时间,这个结果会受到影响,你可以尝试nanoTime()方法。另外 猜测啊 是否和多核有关系呢? mLastTime 初始化值 是否为0?
      

  2.   

    有可能和多线程有关, mLastTime当然初始化为零0了