It's going to be a mobile app, and that's an excellent question. Honestly, I'm not sure yet. I think unfocused because a player might still have that app open but not be playing it, in which case the function still needs to run. But the function would have to work in both scenarios, unfocused and closed.
How do I detect either of those?
that's why i asked also, cause i never done it before, was thinking u already solved it, from my knowledge if is unfocused the app won't run any background events cause automatically pauses itself unless im mistaken.
and if u use the mobile app service thing button to force close the app is again unfocused so it won't know is being closed... this is a tricky thing to do on mobile. unless u can detect the input of mobile that shows all apps running and then quickly tell the app to save progress when the user touched that input... but probably saving progress every 1 minute would do the trick. but then ul have a 1 minute gap glitch where people could just get fast energy by closing and reopening it again, before it saves.
id have to test it out though.