Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个有几个活动的 android 应用程序。我需要在第一个活动开始时启动一个计时器,并在最后一个活动开始时结束计时器并显示经过的时间。我如何使用 Asynctask 来做到这一点。
子类Application,声明将由or中的第一个 Activitypublic static long started;分配的 a 。最后读取值并计算增量。 如果您绝对想使用(我认为在这种情况下无关紧要),您至少需要一个中介。System.currentTimeMillis();onCreate()onResume()ActivityAsyncTaskService
Application
public static long started;
System.currentTimeMillis();
onCreate()
onResume()
Activity
AsyncTask
Service
使其成为静态的。为什么你用计时器来计时?使用currentTimeMillis()会更好。