0

Hey i'm hoping somebody could help me out. I see a lot of articles and StackOverflow questions about setting alarms but I am a little confused as to how to set up an android alarm for my specific situation. Basically, I have an AsyncTask that downloads data from a server and then updates a ListView. I want that to be run every day at 12:00 AM. If the phone is turned off, it should run when the phone wakes up. If the phone is on but there is no network, it should run the next time an active network is available or at least try running every 30 min until it is successful.

Hopefully someone in this awesome community could show me how its done :-)

  • Please show the code you have tried so far – Beryllium Mar 26 '14 at 18:27
  • I haven't tried any code for creating an alarm yet since I'm not quite sure where to begin. Here is a GitHub link with the project I am working on. The classes I want to work with are MainFragment and GetZmanimMap https://github.com/AlexAbraham1/ZmanIt/tree/master/ZmanIt – Alex Abraham Mar 26 '14 at 18:59

1 Answers1

0

I think you should have a look at RxJava, which let's you schedule and repeat tasks. Have a look at the main wiki here and the page for a timer here.

This sample shows how to do a print out every 24 hours

Observable.timer(24, TimeUnit.HOURS).repeat().subscribe(new Action1<Long>() {
        @Override
        public void call(Long aLong) {
            System.out.println("Repeated every 24 hours");
        }
    });

In regards to handling a device boot have a look at this SO question.

Hope this helps you get started.

Community
  • 1
  • 1
Mellson
  • 2,918
  • 1
  • 21
  • 23