0 votes

Hi everyone,

in my mobile app I'm working on, a counter is continuing to count up. Putting it into onscreen == MainLoop.NOTIFICATION_WM_FOCUS_OUT: and later back to „focus in“ again, on Windows 10 the counter did not interrupt but shows the „right“ number, so I assume it just continued running in the background. On Android, however, it interrupts, resuming counting from where it focussed out (which is too bad...).
I'd be very interested if someone could tell me why Windows doesn't interrupt.

However, my main question on that note is, naturally: how does an alarm-app on the phone keep running in the background?
These you can (assumingly?) close down completely after setting an alarm (or a timer...), but something has to continue running in the background so it can fire up at the right time.

Is there any way to have a Godot-made program do the same?

Godot version 3.3
in Engine by (365 points)
  • how does an alarm-app on the phone keep running in the background?

They probably hook directly into the operating system because they're programming in an android app developing environment. There are a lot of things you can do while programming an android app natively that you can't do when exporting a Godot game to android.

  • Is there any way to have a Godot-made program do the same?

Unless someone else knows otherwise, I highly doubt it.

Alright, that makes sense. Thanks for your answer!

1 Answer

0 votes
Best answer

The fact than your mobile device is attached to a battery, each Android app goes through a life cycle to ensure optimal power and memory (ram) usage.

So the system kills apps or places them in a dormant state for this reason simulating multiple tasks switching

Desktops have no such limitations and as such chrome can suck all the resources it wants while you run other apps in the foreground

What both OS's have in common though are services and the very reason your alarm can go off even if your phone is switched off. In fact Google has about 8 constantly active ones collecting data

You'll need to familiarize yourself with the Android services framework

And one can probably be started using Godot's OS.execute() with the am start -a android.intent.action.MAIN -n command (not tested) by using the custom build template

by (4,484 points)
selected by

That makes sense as well, thanks for the insight.

I see that I would have to do some extra steps using focus in/out (maybe some update-calculations to bridge the time-gaps) when "returning back to the app" on the phone...

Services! Already intimidating ; ) But thanks for the hint, maybe I can get into this a bit.

Yes yes this answer was in relation to your query.

A less complicated solution would be to record the time at focus out then at focus in subtract the current time from the recorded one

counter = current_time - focused_out_time

The downside to this approach would be time glitches and incorrect clocks

This is exactly my approach!

In that wake, is it right that OS.get_datetime() goes down to (only) seconds whearas OS.get_system_time_msecs() to, well, milliseconds? I can't have the datetime accuracy down to msecs, can I?
Actually, I'd like accuracy running on tenth 0.0 of a second... would I have to calculate that out of system_time? (But couldn't out of datetime?)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.