Search code examples
cordovaionic-frameworkhybrid-mobile-app

Cordova + Ionic App run in background and resume to the last screen


I'm developing a new version of an app that is a kind of stopwatch that after some amount of time make a step or reach a checkpoint. This stopwatch should be run hours and hours and hours without stop.

When the app works in foreground there are no problems but when the app pass in background some strange happens and after a some amount of time seems that the app is killed, and when I come back to the app is restarted.

The old app made with cordova + sencha touch I don't had this behavior and could stay days running in background (without using plugins to do this).

I don't necessarily need that the app stay running in background because I only need to know when the stopwatch was started, I only would like to come back and resume the app to the last screen.

How can I do?

Thanks!


Solution

  • There are many things that could happen meanwhile the app is in background, so you could probably save the current app state on the app exit/pause event, save the clock time.

    Once the user return, somehow read your last state, "recreate" the last state, check the current time and compute the time that has passed to update your stopwatch.

    You could probably rely on a server time instead of the device time.