我有一个相当简单的应用程序,它是用 Clojure 编写的,并希望定期自动执行其中一个功能。我正在尝试使用 AndroidAlarmManager
来安排任务。这是我到目前为止所拥有的:
Android 的参考文档在此处输入链接描述
public class HelloIntentService extends IntentService {
/**
* A constructor is required, and must call the super IntentService(String)
* constructor with a name for the worker thread.
*/
public HelloIntentService() {
super("HelloIntentService");
}
/**
* The IntentService calls this method from the default worker thread with
* the intent that started the service. When this method returns, IntentService
* stops the service, as appropriate.
*/
@Override
protected void onHandleIntent(Intent intent) {
// Normally we would do some work here, like download a file.
// For our sample, we just sleep for 5 seconds.
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// Restore interrupt status.
Thread.currentThread().interrupt();
}
}
}
我自己在 Clojure 中的进步:
(gen-class
:name adamdavislee.mpd.Service
:extends android.app.IntentService
:exposes-methods {IntentService superIntentService}
:init init
:prefix service)
(defn service-init []
(superIntentService "service")
[[] "service"])
(defn service-onHandleIntent [this i]
(toast "hi"))
我想我误解了一些微妙的东西;在评估第一个 sexp 之后,符号adamdavislee.mpd.Service
未绑定,符号 也未绑定superIntentService
。