Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: execute doWork not only based on a time, but also on demand. #14

Closed
teusink opened this issue Sep 2, 2013 · 13 comments
Assignees

Comments

@teusink
Copy link

teusink commented Sep 2, 2013

This to make it possible to bind an listener to the app.

Example:

  • Listen to a shake with the phone.
  • Execute code when shake happened.
  • Listen again for a shake.

Stackoverflow example code: http://stackoverflow.com/questions/2317428/android-i-want-to-shake-it

@Red-Folder
Copy link
Owner

Is the intention to run code in the background (java) or in the foreground (javascript)?

@teusink
Copy link
Author

teusink commented Sep 2, 2013

Intention is to create a listener that runs Java code. Roughly the same as it is now, only without the timer.

@Red-Folder
Copy link
Owner

Code written. Just need to test and upload. Hopefully get a chance this weekend.

@ghost ghost assigned Red-Folder Sep 13, 2013
@teusink
Copy link
Author

teusink commented Sep 13, 2013

Wow, awesome!

www.teusink.org
www.droidpapers.org
Op 13 sep. 2013 17:55 schreef "Red-Folder" notifications@github.com het
volgende:

Code written. Just need to test and upload. Hopefully get a chance this
weekend.


Reply to this email directly or view it on GitHubhttps://github.com//issues/14#issuecomment-24404419
.

@Red-Folder
Copy link
Owner

Added runOnce() support this morning. This can be run from Javascript (via the Plugin) or from the Background Service.

The runOnce() will run the doWork() then update the latest result (in the same manner as the timer does). This means that reading the LatestResult within your Javascript will return the result of the runOnce execution (assuming it was the last to run).

Neither the Plugin or Background Service runOnce() accept any parameters - so if you need data to work on in your doWork() then you will need to pass this out-of-band. For the Plugin (from Javascript) I'd recommend sending the data in setConfig. For the Background Service I'd recommend setting a member field/ variable.

I'll leave this issue open until such time as I've had a chance to document an example of its use.

@teusink
Copy link
Author

teusink commented Sep 20, 2013

@Red-Folder Nice! I hope I have sunday time to test it. I will add a listener for a shake and upon shake code will be executed. I will let you know what the outcome is. Thanks!

@teusink
Copy link
Author

teusink commented Sep 23, 2013

I am testing with it, and pretty much everything seems to work.

I notice that after the service is started, the runOnce is not automatically run. When it comes to biding listeners in the service this is not handy. Because sometimes Android restart services and the listener is gone. I have to manually do a runOnce in order to get things back to working.

Any thoughts on this?

@Red-Folder
Copy link
Owner

Override protected abstract JSONObject initialiseLatestResult();

Put the listener setup in there. This should be called if Android restarts the service.

Let me know how you get on

@teusink
Copy link
Author

teusink commented Sep 24, 2013

That should probably do the trick indeed. I will test that out.

Another question. Since I run the latest version somehow the getStatus doesn't result in a succes callback (or something). I had nested some things like this:

autochanger.getStatus( function (r) { handleAutoChangerSuccess(r); }, function (e) { handleAutoChangerError(e); } );

function handleAutoChangerSuccess(data) { if (!data.ServiceRunning && handleAndroidPreferences("get", window.androidPrefsLib, "settingAutoChanger", "") === "on") { console.info("PhoneGap Plugin: AutoChanger Service: started service, because it should be running."); serviceAutoChanger("startService", "none"); } if ($.mobile.activePage.is('#wallpaperSettingsPage')) { updateView(data); } }

The callback of the getStatus command is the handleAutoChangerSucces part. When the service is not running it should automatically start it.

Edit:
Never mind. It is the "handleAndroidPreferences" part. The callback takes to long or something to properly do the comparison.

@teusink
Copy link
Author

teusink commented Sep 24, 2013

Never mind. It is the "handleAndroidPreferences" part. The callback takes to long or something to properly do the comparison.

@vladjiss
Copy link

Please help me, I have a error: Error: Plugin unable to bind to background servace
ErrorCode: -4 ...
I do everything according to instructions.
http://zalivalka.ru/79472
Who has a working source code, send me please danreegly@gmail.com

@Red-Folder
Copy link
Owner

@vladjiss Please stop adding comments to existing issues. The issue should be kept on topic. Please create a new issue and provide a copy of your code so that I can assist. It will almost certainly be because you have missed a step in the instructions - which I'm prepared to help with, but please stop spamming the issues list

@Red-Folder
Copy link
Owner

I have now documented the runOnce functions, these can be found in the new repo WIKI:

Now documented I consider this issue closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants