10-08-2014, 01:09 AM | #1 |
Junior Member
Posts: 4
Karma: 10
Join Date: Oct 2014
Location: Seattle area
Device: Kindle 4 Non-Touch
|
Timer issues
Good day all,
I was exploring the world of kindle development, and as a simple introductory project (and potentially useful application) I thought I would make a clock app that periodically shows the time on the e-ink screen. (This would be nice to replace a digital alarm clock as the e-ink screen does not produce any ambient light). However, I've run into some difficulties. Namely, the kindlet library Timer class does not seem to be firing its scheduled tasks. I've tried several variations of the schedule methods and different assumptions about the value it is accepting for delay/period arguments, but nothing seems to be working. It will run its task once, but won't update on the period it is supposed to and only runs subsequent updates when the kindle is awoken from the lock screen. Specific snippets of my code will be at the bottom of this post. More than a simple solution for this, though, I'd like to know if there are any additional resources available for learning the kindle libraries. They don't seem to have any javadocs (in the case of the timer, since the API is the same I would assume it would work the same as the java util class of the same name, though my problems would indicate otherwise) and examples are sparse. I do appreciate the number of kindlets posted here which are open sourced on github, but these can be difficult to read through and are typically based around a very event-oriented control flow as far as I can tell. Thanks for your time, Andrew My main class: Spoiler:
|
10-08-2014, 02:27 AM | #2 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Your only problem is that the cpu is shutting down.
Search this forum for things such as "kindle clock" - There are ways out of your problem. Forum usage foo: https://www.mobileread.com/forums/sho...d.php?t=237083 And don't forget about the filtering of this index by topic prefix. Last edited by knc1; 10-08-2014 at 02:31 AM. |
Advert | |
|
10-08-2014, 09:56 AM | #3 |
Wizard
Posts: 1,379
Karma: 2155307
Join Date: Nov 2010
Location: Goettingen, Germany
Device: Kindle Paperwhite, Kobo Mini
|
Timer.schedule() schedules the task once. So everything is working as it should. OP is probably looking for Timer.scheduleAtFixedRate(). Documentation is sparse, but available: http://kdk-javadocs.s3.amazonaws.com...til/Timer.html Note the difference between "fixed delay" and "fixed rate".
|
10-08-2014, 10:06 AM | #4 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Thanks!
All I could remember for certain is that people have solved the problem of scheduling while the cpu sleeps. - - - - 66 00 - I gotta get a real life. |
10-08-2014, 04:41 PM | #5 | |
Junior Member
Posts: 4
Karma: 10
Join Date: Oct 2014
Location: Seattle area
Device: Kindle 4 Non-Touch
|
Quote:
I don't see anything in there about why fixed-delay and fixed-rate would be any different, but if CPU sleeping was an issue I guess I could see why one would work over the other. However, I don't think either of them are working: Just updated my code to use the scheduleAtFixedRate method and it's still not running the update (again unless you lock/unlock): Huge phone screenshot Updated portion of code: Code:
t = new Timer(); t.scheduleAtFixedRate( new UpdateTimeTask(this), new Date(), // Execute first now 15000L // Spacing between executions (15 s) ); (Also, just to be sure it was indeed running an updated version of the app, I had a couple of intermediate builds where I was playing with adding a version label. Didn't figure out any solution for the moment but I know it's running the new code.) Thanks again for the help |
|
Advert | |
|
11-12-2014, 12:52 AM | #6 |
Junior Member
Posts: 4
Karma: 10
Join Date: Oct 2014
Location: Seattle area
Device: Kindle 4 Non-Touch
|
Just as a follow up, I came back to this after leaving it for a month or so and got it working a different way. I never got the timer working, but I was able to achieve the same result with a thread:
Spoiler:
This works when the kindle is freshly started. However, I noticed that it doesn't exit cleanly. I do have a destroy method that looks like this: Spoiler:
But it doesn't seem to be working properly. If I abort the restart when the kindle notices the failure, and relaunch the app, it no longer updates. That seems odd, since it should be creating a new instance. I don't really know how kindlet session/lifecycle management works, so I just shrugged and ignored it. As long as I only run the app once per session, it works fine. Anyway, thanks again for the help with this. I don't know if I'll continue making anything for the kindle, as I prefer development environments that aren't actively working against me, but it was an interesting experience nonetheless. |
11-12-2014, 02:02 AM | #7 |
Wizard
Posts: 1,379
Karma: 2155307
Join Date: Nov 2010
Location: Goettingen, Germany
Device: Kindle Paperwhite, Kobo Mini
|
So now you know why all the fancy apps here - with the notable exception of KUAL - do not use the Kindlet framework :-)
|
11-12-2014, 10:23 PM | #8 | |
Junior Member
Posts: 4
Karma: 10
Join Date: Oct 2014
Location: Seattle area
Device: Kindle 4 Non-Touch
|
Quote:
For posterity, I've dumped the source code into a zip and attached it to this post. Still haven't nailed down the bad thread exit, but with debug tools being what they are (functionally nonexistent), it doesn't really feel worthwhile to try and track down something that will only affect me when the app closes - which, since I'm using it as an actual clock, will end up being not very often. *Come to think of it, it wouldn't be that much worse than signing the jar every time, which I automated with a batch file. Still. |
|
Tags |
java, kindle 4, timer, timertask |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
First timer | GrannyPan | Introduce Yourself | 7 | 06-29-2011 12:34 AM |
First Timer | EMJESS | Introduce Yourself | 3 | 06-24-2011 08:45 PM |
Unutterably Silly Using an electronic timer | lene1949 | Lounge | 15 | 09-11-2010 10:36 PM |
Hello from an old new-timer | ebuyer099 | Introduce Yourself | 1 | 05-21-2010 01:34 PM |
first timer | ChrisM12743 | Introduce Yourself | 3 | 03-29-2008 11:35 AM |