Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 设置计时器以测量应用程序运行的时间_Java_Android_Timer_Adt - Fatal编程技术网

Java 设置计时器以测量应用程序运行的时间

Java 设置计时器以测量应用程序运行的时间,java,android,timer,adt,Java,Android,Timer,Adt,我有兴趣在我的应用程序“统计”页面中添加“播放时间”行。然而,我需要一个好的方法来衡量我的应用程序被打开的时间。 设置此项的最佳和最有效的方法是什么? 我的应用程序由多个活动组成,因此它需要能够运行任何活动。 我的MainActivity从不关闭,它会打开关闭onFinish()的其他活动。所以我想在MainActivity期间可能会运行计时器?在onResume中获取时间戳,在onPause中获取新的时间戳并保存差异。这两种方法都保证作为活动生命周期的一部分被调用。如果前台的主要活动范围不足,

我有兴趣在我的应用程序“统计”页面中添加“播放时间”行。然而,我需要一个好的方法来衡量我的应用程序被打开的时间。 设置此项的最佳和最有效的方法是什么? 我的应用程序由多个活动组成,因此它需要能够运行任何活动。
我的MainActivity从不关闭,它会打开关闭onFinish()的其他活动。所以我想在MainActivity期间可能会运行计时器?

在onResume中获取时间戳,在onPause中获取新的时间戳并保存差异。这两种方法都保证作为活动生命周期的一部分被调用。如果前台的主要活动范围不足,您可以使用用户首选项存储值或将其传递给新活动。

在onResume中获取时间戳,在onPause中获取新时间戳并保存差异。这两种方法都保证作为活动生命周期的一部分被调用。如果前台的主要活动范围不足,您可以使用用户首选项存储值或将其传递给新活动。

在onResume中获取时间戳,在onPause中获取新时间戳并保存差异。这两种方法都保证作为活动生命周期的一部分被调用。如果前台的主要活动范围不足,您可以使用用户首选项存储值或将其传递给新活动。

在onResume中获取时间戳,在onPause中获取新时间戳并保存差异。这两种方法都保证作为活动生命周期的一部分被调用。如果前台的主要活动范围不够,您可以使用用户首选项存储值或将其传递给新活动。

我还认为最好使用时间戳,而不是运行线程和使用系统资源,如内存、cpu。。。在应用程序的开始/结束时使用时间戳应该更有效。

我还认为最好使用时间戳,而不是运行线程和使用系统资源,如内存、cpu。。。在应用程序的开始/结束时使用时间戳应该更有效。

我还认为最好使用时间戳,而不是运行线程和使用系统资源,如内存、cpu。。。在应用程序的开始/结束时使用时间戳应该更有效。

我还认为最好使用时间戳,而不是运行线程和使用系统资源,如内存、cpu。。。在应用程序的开始/完成时使用时间戳应该更有效。

使用共享首选项,并在应用程序启动时存储开始时间

System.currentTimeMillis()//以毫秒为单位的当前时间

一开始

    SharedPreferences preferences = context.getSharedPreferences("SomeApp", 0);

    SharedPreferences.Editor editor = preferences.edit();
    editor.putLong("startTime", System.currentTimeMillis() );
    editor.commit();
然后在任何时候,你都可以把这个值拉出来,计算出播放的时间

  SharedPreferences preferences = context.getSharedPreferences("SomeApp", 0);
  long start = preferences.getLong( "startTime" );

  long timeRunInMillis = System.currentTimeMillis() - start;

timeRunInMillis将是应用程序运行的时间,以毫秒为单位。

使用共享首选项,并在应用程序启动时存储启动时间

System.currentTimeMillis()//以毫秒为单位的当前时间

一开始

    SharedPreferences preferences = context.getSharedPreferences("SomeApp", 0);

    SharedPreferences.Editor editor = preferences.edit();
    editor.putLong("startTime", System.currentTimeMillis() );
    editor.commit();
然后在任何时候,你都可以把这个值拉出来,计算出播放的时间

  SharedPreferences preferences = context.getSharedPreferences("SomeApp", 0);
  long start = preferences.getLong( "startTime" );

  long timeRunInMillis = System.currentTimeMillis() - start;

timeRunInMillis将是应用程序运行的时间,以毫秒为单位。

使用共享首选项,并在应用程序启动时存储启动时间

System.currentTimeMillis()//以毫秒为单位的当前时间

一开始

    SharedPreferences preferences = context.getSharedPreferences("SomeApp", 0);

    SharedPreferences.Editor editor = preferences.edit();
    editor.putLong("startTime", System.currentTimeMillis() );
    editor.commit();
然后在任何时候,你都可以把这个值拉出来,计算出播放的时间

  SharedPreferences preferences = context.getSharedPreferences("SomeApp", 0);
  long start = preferences.getLong( "startTime" );

  long timeRunInMillis = System.currentTimeMillis() - start;

timeRunInMillis将是应用程序运行的时间,以毫秒为单位。

使用共享首选项,并在应用程序启动时存储启动时间

System.currentTimeMillis()//以毫秒为单位的当前时间

一开始

    SharedPreferences preferences = context.getSharedPreferences("SomeApp", 0);

    SharedPreferences.Editor editor = preferences.edit();
    editor.putLong("startTime", System.currentTimeMillis() );
    editor.commit();
然后在任何时候,你都可以把这个值拉出来,计算出播放的时间

  SharedPreferences preferences = context.getSharedPreferences("SomeApp", 0);
  long start = preferences.getLong( "startTime" );

  long timeRunInMillis = System.currentTimeMillis() - start;

timeRunInMillis是应用程序运行的时间,单位为毫秒。

谢谢,我必须研究一下这个方法!:)研究时间!谢谢,我得研究一下这个方法!:)研究时间!谢谢,我得研究一下这个方法!:)研究时间!谢谢,我得研究一下这个方法!:)研究时间!