0

I want to create a alarm function which is running in background even I exit from the application but not based on time. The function which checks for the value from the database, if the condition satisfies the alarm will arise... How to do this?

2 Answers2

1

Seems that you're looking for a Service. They have the ability of being run even if your foreground app is not, but the disadvantage that you'll have to be aware it can be killed if the Android OS needs memory, especially if you're using too much resources.

It's also necessary to handle correctly the events where your Service may get created/destroyed, so you simply run your Service where you need and stop it when you no longer need it.

Some useful links:

nKn
  • 13,691
  • 9
  • 45
  • 62
1

Start a service which can run indefinitely.

your service would be a content observer or polling the database periodically.

Sqlite Database updates triggers Service to update via Content Observer

Community
  • 1
  • 1
danny117
  • 5,581
  • 1
  • 26
  • 35