-1

Im new to android development and Im developing an app which schedule the sms to send with given specific time. Sending time has been saved in SQLLITE DB. IF the time has been reach to the DB time SMS should be sent. I can achieve the SMS sending part but not to check the time.

I know that i need to use Android AlarmManager and i know how to use it.

My problem is to get the time from DB and check the check with Device time.(Kind of service)

  • Use android alarm manager to send an event to your app for specific time and send the sms on your required time. – Ali Imran Oct 28 '13 at 07:35

3 Answers3

1

First of all i would suggest Alarm Manager is too much heavy to use. I would prefer you to write a synchronous class using mutithreading which trigger your task

The postdelay option does the trick of alarm manager.

Its your choice to make that synchronous class a service one.

I came across few examples regarding this synchronous classes for android one of them is

Android: execute code in regular intervals

The accepted answer will help you how to write an syn class which triggers your need.

Its now easy for you to place your db value in postdelay function for dynamic delays.

Community
  • 1
  • 1
sam
  • 2,426
  • 2
  • 20
  • 29
1

Yes need to use AlarmManager, but I think it would not be a good approach to keep looking database to check how many messages are pending to send and weather it has got the time to send or not.

Defiantly you need to write a background service for that, But do you think its a good approach?

  • Will this service keep looking in db all the time? (Too much resource consuming)
  • What period will you set if you want to run service periodically? (Compromise on time accuracy of sending)

Its AlarmManager which is most appropriate for this. Just initialize a alarm when you are making entry in db right now. Make you alarm to be RTC_WAKEUP, so that it can send message even the phone is powered off. And every thing will be handled by android itself.

Yes can use database still to have record of all the messages sent by you application, pending to sent, sent successfully, failed etc. Means make entry with messages and its status in db, and just update on respective events like update it to successfully sent when alarm triggered.

Long story, but hope this helps...

umair.ali
  • 2,714
  • 2
  • 20
  • 30
0

Use GCM Intent Service. It is used to run a particular code even when your app is idle or in background. In that class, write a handler or a timer, having your code. This approach you can try or look into it

Rahul Gupta
  • 5,275
  • 8
  • 35
  • 66