J'ai une application assez simple, que j'ai écrite dans Clojure et que je voudrais exécuter automatiquement l'une de ses fonctions périodiquement. J'essaie d'utiliser AlarmManager
d'Android pour planifier la tâche. Voilà ce que j'ai jusqu'à présent:Création d'un service Android dans Clojure
Documentation de Android pour référence 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();
}
}
}
Mon progrès dans 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"))
Je pense que je suis malentendu quelque chose de subtil; après avoir évalué le premier sexp, le symbole adamdavislee.mpd.Service
est non lié, et le symbole superIntentService
non plus.
Merci; Je me rapproche maintenant, en particulier cela m'a aidé à réaliser que 'superIntentService' était exposé comme une méthode et non un symbole régulier. –