-3

I have a requirement as below: On tapping a button on a view ,a timer should be activated for 5 minutes.And timer should continue it's execution if the application is moved to background and if the application is killed from background.Please help.

Vork
  • 746
  • 2
  • 12
  • 34
  • 1
    What is this timer trying to achieve at the end? – valosip Sep 18 '19 at 17:15
  • Only once timer has ended after 5 min, user can proceed with further action from front end. – Vork Sep 19 '19 at 02:34
  • You can use a work around by setting a local notification to alert user of timer being up if app is in background, with combination of storing/checking a time value in a db or user defaults. This entire flow seems a bit odd to me. – valosip Sep 19 '19 at 04:40

1 Answers1

3

That is not possible. Apps get suspended shortly after they are swapped out for another app (A suspended app is still in memory but does not get CPU time.) Once suspended an app can be terminated at any time without warning.

You can request background time, but you are limited to 3 minutes. Only a few types of applications (e.g. music players and turn-by-turn navigation apps) are allowed to run continuously.

If you need your app to be notified at some future time, you should consider creating a local notification with a future "fire date". That will wake up your app and give it a chance to respond (assuming the user taps the notification to send it to your app.)

Duncan C
  • 128,072
  • 22
  • 173
  • 272