0

In my Android application, I want to run some form of a background process, which checks a few conditions every 10 minutes. If a condition is satisfied, I want to show an AlertDialog box or some form of notification to the user.

How can I do this? Can anyone provide some source code as a reference point?

I have tried running a new Thread in the Activity onCreate() method, but wasn't able to get too far with that.

Thanks!

2 Answers 2

1

I would use a IntentService with AlarmManager, to call it every X minutes.

The reasons I would suggest that, and not using a background thread that sleeps for 10 minutes each time, are two:

  1. You are wasting resources.
  2. The android platform already supply you with great services, why not using them?
0

Create your own Service that has a background thread that loops for 10 mins, this way you can have all your other complicated logic run in this service.

You might find this link helpful.

I think you will face a problem when you try to create a dialog from a background service, as dialog box can not be created from a Service's context.

A solution will be to have an activity launched in the dialog theme via an intent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.