Keep Timer Running While App Is Closed

Hello!

Is there a way to keep a timer running even when an app is ‘closed’ or ‘suspended’?

I’m working on a two player game where I need the timer to keep running while it waits for the other player to move.

I’ve been searching but can’t seem to find what I’m looking for.  Right now I have it written using timer.performWithDelay( ) but I’m not sure if it would be better to somehow relate it to os.clock ( ) or if I just need to use the application suspend, exit, etc API’s or what to keep the timer running.

I basically want the timer to keep running until it reaches the time limit regardless of the application state.  I haven’t actually set it up for multiplayer yet but I think that’s about all that’s left to do.  Any help would be much appreciated!

thank You!

Sounds like you might be interested in Local Notifications.  See: http://docs.coronalabs.com/guide/events/appNotification/index.html

Rob

I’m not sure if I read that right but it seems like it’s just for sending notifications to the other user?  I have a visible timer (text updates according to timer.performWithDelay) for each player so I need to keep track of the time in order for the text to be updated appropriately. The problem is that it’s not the time since the last move, but rather keeps track the total time a player takes to make all moves during course of the game.

It’s kind of difficult to describe I guess but basically:

Player A has x amount of time to make any moves.

Player B has y amount of time to make any moves

Once player A or player B reaches x or y total time, respectively, the game ends

So I need to keep track of total x and total y and update the associated text, not necessarily notify the users that it’s their turn?

 I would save the users ‘start timestamp’ into sqlite along with the timestamp when the app closes (there are runtime events that will fire at appClose, appSuspend, etc).  The next time the user starts the app, fetch these values and compare against the current timestamp to calculate their total time up to that point.

As Rob noted, you can use local notifications to alert the user that their turn is about to expire in X seconds as the app is closing.  This would be handy because you an figure out how much time a user has left, subtract a couple minutes from that, and then schedule the local notification (which the OS handles while your app is closed).  Note, this won’t open the app though, the user would still have to launch the app manually (or via the notification).

Local notifications are not for sending messages to your device from another source.  That’s what push notifications are for.  Location notifications are used for setting triggers in the future so your app can respond.  Think of it like setting an alarm with the clock app, or reminders with the reminder app…

Rob

Hi. I think that my problem is relative to this matter. I want send notification, under any conditions, when the app is closed too. How i could do it?Thanks.

If your app will be notifying itself, you would use local notifications.  The guide link is above.   If your app needs notified by some outside influence, then you would use push notifications.

Mmmm i have to manage notifications to show when a new video is loaded in a youtube playlist; to check if there is a new video i store the data of last published video and i verify all new incoming video date. So, i think i can use local notifications. (?)

Sounds like you might be interested in Local Notifications.  See: http://docs.coronalabs.com/guide/events/appNotification/index.html

Rob

I’m not sure if I read that right but it seems like it’s just for sending notifications to the other user?  I have a visible timer (text updates according to timer.performWithDelay) for each player so I need to keep track of the time in order for the text to be updated appropriately. The problem is that it’s not the time since the last move, but rather keeps track the total time a player takes to make all moves during course of the game.

It’s kind of difficult to describe I guess but basically:

Player A has x amount of time to make any moves.

Player B has y amount of time to make any moves

Once player A or player B reaches x or y total time, respectively, the game ends

So I need to keep track of total x and total y and update the associated text, not necessarily notify the users that it’s their turn?

 I would save the users ‘start timestamp’ into sqlite along with the timestamp when the app closes (there are runtime events that will fire at appClose, appSuspend, etc).  The next time the user starts the app, fetch these values and compare against the current timestamp to calculate their total time up to that point.

As Rob noted, you can use local notifications to alert the user that their turn is about to expire in X seconds as the app is closing.  This would be handy because you an figure out how much time a user has left, subtract a couple minutes from that, and then schedule the local notification (which the OS handles while your app is closed).  Note, this won’t open the app though, the user would still have to launch the app manually (or via the notification).

Local notifications are not for sending messages to your device from another source.  That’s what push notifications are for.  Location notifications are used for setting triggers in the future so your app can respond.  Think of it like setting an alarm with the clock app, or reminders with the reminder app…

Rob

Hi. I think that my problem is relative to this matter. I want send notification, under any conditions, when the app is closed too. How i could do it?Thanks.

If your app will be notifying itself, you would use local notifications.  The guide link is above.   If your app needs notified by some outside influence, then you would use push notifications.

Mmmm i have to manage notifications to show when a new video is loaded in a youtube playlist; to check if there is a new video i store the data of last published video and i verify all new incoming video date. So, i think i can use local notifications. (?)

Rob we need something that it is not timed, we need something that if an event occurs a local notification will be sent to the device. we get local notifications function but we need to make a runtime/timer still be running even if the app is suspended

What kind of events?

Rob we need something that it is not timed, we need something that if an event occurs a local notification will be sent to the device. we get local notifications function but we need to make a runtime/timer still be running even if the app is suspended

What kind of events?