ceran
ceran

Reputation: 1412

Android: a component for background processing that has to be started manually

I need your thoughts. What I'm looking for is a task or service, running in the background (no UI), capable of the following:

In other words: The user does not trigger the processing, the user is just responsible for the input. The AlarmManager then triggers the processing periodically.

Is the android service class suitable for that or is there a better way to go?

If yes, I have a problem understanding the service class. According to the docs, it does not have its own process but runs in the host process. Could this lead to problems? So sometimes the phonegap plugin (which passes the data) is the host process and sometimes the alarm code is the host process, or I am wrong? I mean the service has no main application, it is rather something independent that can be called from different locations.

Thanks

Thank you

Upvotes: 1

Views: 244

Answers (2)

mcnicholls
mcnicholls

Reputation: 846

A service would be appropriate here.

You can schedule AlarmManager to call your Service at intervals and have your UI Activity push data to it and optionally wake the service up to process the data.

A Service runs in the host process and will run in the UI thread unless you create another thread. The IntentService class can help you with this. It allows you to fire intents off that get handled by the service in a worker thread.

The intents are queued up in the IntentService class and are processed in turn by a single worker thread that is managed by IntentService.

In your case, you can have the AlarmManager fire off an Intent that would be handled by your service in the worker thread.

Upvotes: 2

herom
herom

Reputation: 2542

please consider that AlarmManager gets lost of all alarms set once the phone is rebooted, to initialise the alarms again it is common to create an OnBootReceiver derived from BroadcastReceiver to get notified when the phone was rebootet. then you'll have to set the alarms again.

Upvotes: 2

Related Questions