So, I'm trying to make a sudoku app for Android at the moment, and one pretty big feature is to have a timer so you can be competitive with the puzzles and see how long it takes. Unfortunately though, at the moment when you minimise the app/change apps or whatever, the time continues, since LC doesn't have a specific way to realise when it's in the background and needs to stop. That said, even though LCS doesn't have that, LCB does, with AndroidRegisterLifecycleListener - though I'm getting myself quite confused about it at the moment.
This is my first look into LCB and trying to wrap my head around it all, but I've managed to make some simple libraries (like the Hello World one included in the lessons for example), but even with that, can't quite get how this one works.
I've got this code up at the moment as per the dictionary:
Code: Select all
library community.livecode.opaquer.androidlistener use com.livecode.engine use com.livecode.java use com.livecode.library.androidutils -- metadata private variable mLifecycleListener as optional JObject public handler OnOpen() returns nothing put AndroidRegisterLifecycleListener(OnMyWidgetPaused,OnMyWidgetResumed) into mLifecycleListener end handler public handler OnClose() returns nothing AndroidUnregisterLifecycleListener(mLifecycleListener) put nothing into mLifecycleListener end handler private handler OnMyWidgetPaused() returns nothing -- perform pause actions end handler private handler OnMyWidgetResumed() returns nothing -- perform resume actions end handler end library
Code: Select all
private handler OnMyWidgetPaused() returns nothing AndroidInBackground end handler
My next issue though is that since this is supposed to be listening for when the app goes in the background/comes back, where do I put this in my stack? Do I just have it installed somewhere, or do I need to run something in my preOpenStack code or whatever to tell it to start listening? The dictionary definition for OnOpen says that handler is sent when the widget containing that card opens, but if I'm just writing a library how do I get it to do that?
Sorry if this is all very basic stuff, it's really doing my head in!
Thanks in advanced!