0

我正在尝试实现一些允许我计算用户使用该应用程序的时间的东西,但它似乎很难或至少编码复杂。我尝试了几次尝试和逻辑,但都失败了。

我不确定这是否是写的,但我创建了两个变量,如下所示

    static Date startTime = new Date();
The startTime variable goes in the main activity and it notes the time user launched the app.


     static Date endTime = new Date();
The endTime goes in the onDestroy method and takes the time when the user closes the app.

If this approach is write, I understand I would need to find out the different between the two times but I am not sure how to attempt something like this. Could someone please help, what I want to be able to do is get a final value and pass it to the code below and send it over to Google Analyst for Android;

/*
 * Called after a list of high scores finishes loading.
 *
 * @param loadTime The time it takes, in milliseconds, to load a resource.
 */
public void onLoad(long loadTime) { // I need to put my value instead of loadTime, but I cannot figure out how to find the difference between two times.

  // May return null if EasyTracker has not been initialized with a property
  // ID.
  Tracker easyTracker = EasyTracker.getInstance(this);

  easyTracker.send(MapBuilder
      .createTiming("resources",    // Timing category (required)
                    loadTime,       // Timing interval in milliseconds (required)
                    "high scores",  // Timing name
                    null)           // Timing label
      .build()
  );
}

谢谢,我真的很感激任何帮助。

4

1 回答 1

0
endTime.getTime() - startTime.getTime()

这将为您提供两个日期之间的毫秒数。

于 2015-03-23T23:01:14.290 回答