我有一個相當簡單的應用程序,我在Clojure中編寫並希望定期自動執行其中一個功能。我正在嘗試使用Android的AlarmManager
來安排任務。這是我到目前爲止有:在Clojure中創建一個Android服務
Android的文檔爲參考enter link description here
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
也不是。
謝謝;現在我越來越近了,特別是它幫助我們認識到'superIntentService'是作爲一種方法公開的,而不是一個普通的符號。 –