TimerAlwaysFires

Some new issues is coming up.
On some device, the timer is firing after ignoring the battery optimization (i put a BEEP to understand this) but the connection of the app to the internet is missing (web.get gives the error unable to get a response).
Other Apps running in foreground like gmail, have internet connection and work normally, but my app in background just Beeps not being able to connect to the server.
Is there something else related to connection that goes to idle?

You can try to trigger the IGNORE BATTERY OPTIMIZATIONS every sec or (500 ms like I did),
see here (my blocks in Screen1):

Thank you Anke,
ok i will try this in few minutes.
For the moment i am testing an extension by Said_dev LaunchMyApp.WakePhone.
It works, but it's boring to see the phone swicthing on every minute. I don't know if reducing the brightness of the screen (like Taifun suggested) will help.

if you keep the screen on, this will drain your battery, to reduce the brightness only can help to drain the battery less fast...

Taifun

yes i see, but i am looking for something that doesn't look too much "like a workaround".

As Anke suggested I tried to trig the TaifunOptimization.Request before any connection and the connection worked every time the timer fired.
(I'm curious to know and I don't understand why this result is better than to use TaifunOptimization.Request only at start, maybe Taifun can explain?)

But the problem in this case is that the timer fires every minute in the beginning, after a while it fires after 2 minutes, then after 3, then 6 minutes... I am afraid it fires when other apps force the phone to wakeup and not because of my timer.

Till now the best solution seems waking up the phone every minute, but i should add at least a notification to update a message to give a meaning to the workaround, but i tried 2 or 3 extension for notification that didn't work on all the phones.
Can you suggest a good one that i can update every time i wakeup the phone?
Also is there any way to know if my app is in a status of fore/background and if the screen is on/off?
Maybe all these things together will solve my issue.

  • Android is not designed to run apps for long periods of time .

From a previous forum discussion

  • Google revised how long an app can ‘work’ continuously since Android 8. It is not possible to keep alive an app in background or otherwise for a long time (. eg your one or two days).

A few months ago there was a discussion about long term use of a plugged in Android and discussed all the reasons why apps cannot run for long term; essentially because of ‘safeguards’ in the Android system libraries. Sorry, I cannot find it. Perhaps one of the other moderators can.

Your issue is your app/android device shuts down because the Android operating system tells it to. Any way to defeat that is a hack. Keep the device charger plugged in, use a StayAwake routine, limit the battery protections, or run your app on your PC using a games type emulator like BlueStacks (not a nice solution) etc may be the best that is possible

Most of my apps published on the Play Store run all night and they (music) still run in the morning without problems, as many users told me when they forgot to activate the timer. 12 hours and more, isn't that a long period of time?

No. Not when some developers want their apps to run 24/7, the devices not plugged in etc. Did you read the link that explains? And they do not want to use a hack... and a hack is what is required to subvert Google policy.

i agree, a limit in time whould make useless any app.

i've found this interesting link
https://developer.android.com/training/monitoring-device-state/doze-standby
explaining briefly how doze works.
Maybe a good developer of extensions chould make a timer using setAndAllowWhileIdle()
to make apps run in background?

2 Likes

See here: Ottimizza per sospensione e standby delle app  |  App quality  |  Android Developers

How about if you temporarily make a black background visible on the screen when the device switches to idle (sleep) mode, so that when the device wakes up, only this black screen is visible (and thus for the user it is not recognizable that the device has been woken up). :wink:

it would be a good idea but if you have a block on the screen it will not show the app ;(

is this result better? did you test it? I would use it only once at start...

Taifun

after a wonderful pizza i will test it again and i will report the result

If the user e.g. click on the screen, the black background should of course disappear.

when the wakephone switches on the phone i see this

Cattura

sorry I didn't catch what you mean :thinking:

in the wakeup phase my phone switches on (and you see that locked screen) and after some seconds (after exchanging data with the server) it goes off.
Instead of lighting up the screen, It would be nice if i could add a notification (like the one in the picture) with some data about what is happening.
I'm now going to test again the TaifunOptimization.Request (just one instance) and will let you know.

Yes, of course, most people use a lock screen. It was just a (rash) brainstorm of mine ...
since I also tried everything (to no avail) to keep the ExoPlayer running in standby in Kodular.

I made some tests, not so easy to do because the phone wakes up by itself for other reasons, in the condition that my app was in foreground before switching of the display.
The Doze delay, like in the Figure 1, is increasing always in the same way: firing my timer (instead of every minute) after 2 minutes, then after about 3minutes, then after about 5minutes, then even more and stopping also the internet connection. Sometimes the delay starts again from 2minutes probably depending on what is happening from other apps.
This means that for the goal of Doze to save the battery, my users need to keep the phone always switched on, consuming much more battery than with screen off without Doze or they must bring with them a battery pack to simulate the charging condition :smiley:
I didn't find much difference not using TaifunOptimization.Request, or using it in the beginning or every 1sec or 500ms.
Using LaunchMyApp.WakePhone keeps internet connection alive but doesn't allow my timer to be fired with intervals different from 2-7 minutes.
Going to the battery settings page for my app and setting NO RESTRICTION also doesn't change the delay of Doze.
Really looks like the only solution is to keep the phone always switched on, but this is really crazy. Also I don't think this is a limit of App Inventor.
What do you suggest?

I'm working on the issue.
I have some good news you could also test on your apps.
I found that if I activate one or more timers with different interval from 10sec to 500ms, all of them with TimerAlwaysFires=true, the App running with the screen Off, the timer that was firing every 2, 3, 5, 7 minutes instead of 1min, now fires almost every minute.
No wakeup, no taifun restrinction for battery.
Maybe your Timer 500ms was helping for other reasons.
Ops, the manual setting no restriction for battery is set. I will test again without special settings and will let you know.

2 Likes

I've tried similar things, but without lasting success. So show your blocks or post a test aia.

i need to test it better i don't want that the phone was downloading something for other apps and Doze was off :slight_smile: