Red-Folder / Cordova-Plugin-BackgroundService

BackroundService plugin for use with Cordova (PhoneGap)
144 stars 85 forks source link

Current interval timer request. #5

Closed teusink closed 11 years ago

teusink commented 11 years ago

First of all, thanks for this awesome plugin.

As requested I raise this "issue" to tackle the following request.

It would be nice to get the current interval timer of the service. Perhaps a bit same construction like the configuration.

Hope to see this feature in a future release.

Thanks again.

teusink commented 11 years ago

Hi, are you going to implement this feature?

Red-Folder commented 11 years ago

Sorry ... yes, but it might be a while yet (as per the same reasons I gave in the other issue).

Once I've got the automated build & test up and running, the plan of attack is:

I just need to work this in with day job, vacation, etc, etc. I'd like to try and get done in July .... but to be honest I suspect it will be August.

acuatoria commented 11 years ago

Have a question about this. I've got a service that I want to launch once, with startService and I don't want the timer because I've got one Listener in the service. How could I launch the service with no timer? Is it possible or it's needed in order to doWork() ? The issue I have is without enableTimer the service doesn't reach doWork. Thank you very much.

Red-Folder commented 11 years ago

The doWork() is currently called based on the timer. However there is no reason that code cannot be called on some other event (such as a listener).

If you look at the source code for the Background Service (https://github.com/Red-Folder/Cordova-Plugin-BackgroundService-Source/blob/master/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundService.java), you should be able to extend to run the doWork via another method.

Red-Folder commented 11 years ago

Changes made and committed to Github (https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/commit/1bdea8b9bdd4d0710b399fd588afabbce1229fd6#commitcomment-3956440)

TimerMilliseconds is now part of the returned JSONObject

teusink commented 11 years ago

Awesome, just awesome!

teusink commented 11 years ago

@acuatoria Perhaps you can make doWork just sent a message to the log. And then in: `protected void onTimerEnabled() { // TODO Auto-generated method stub }

Add the listener and its code.

Then from your app start the service and enable the timer and set it to daily. To service would run once a day and send a logcat message. But the listener could be active because of timerenabled.

I did not test it, but perhaps it works. But I do not have experience (yet, I need a shake listener) with this construction.

teusink commented 11 years ago

@acuatoria Never mind. Tested it and it seems to be rather unstable... :)

Red-Folder commented 11 years ago

@acuatoria Firstly, would you be so kind as to raise a separate issue for this request (this may end up being an enhancement).

You are correct that there isn't currently a good way to call the doWork without a timer (it can be done ... but is messy).

Under what circumstances would you want to trigger the doWork without a Timer?

I think I may need to amend the base code to allow doWork to be called by both a timer and on demand.

teusink commented 11 years ago

@Red-Folder @acuatoria I opened one: https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/issues/14