App Keep alive always

I have built an mqtt service/process (using Itoo extension) that runs in the background which listens to an ESP32 and updates my app. When the app is closed it sends a notification (notificationstyle extension) and plays an alarm file (using a music player). This is used to alert for a critical situation.

Unfortunately when the mobile goes to doze mode after a few minutes the service stops. This could be a specific problem with my phone (Realme 8i) or the Itoo extension limitation. I have tried disabling every battery saving setting in the phone with no result.

I have also tried the extension "Keep alive" but didn't see any change. I hope I set it up correctly, see screenshot below.

Before I rule out completely this approach has anyone a suggestion ?

Looks like for this to work I will need to do FCM (Firebase cloud messaging) and "high priority messaging" which seems a bit complicated.
In that case I would prefer to use an API with my ESP and make a call using Twilio (paid service).

1 Like

did you check Realme | Don’t kill my app!
also try another device...

the author of the extension @Ulrich_Bien might want to check

Hi Jimlis, could you please try with this simple example first? Like a background countdown, it would help us to know where the issue lies.

So it keeps counting the secs in background, and after your device has killed the background service, it should update no more.

ItooXCount.aia (81.9 KB)

I've been running this for more than a week now (without battery optimizations turned off) on my Stock Android device, and it seems fine.

Just build and install the APK from the AIA attached above, and click the button, leave it running. It will constantly update the secs (updated value will be shown on screen).

Let me know how it goes. It would tell us if the device is really killing the background service.

1 Like

I have just tried my test program for UrskeepAlive again on a Samsung cell phone with Android 12.
The app sends UDP packets at regular intervals so that I can check whether it is still active. It has now been running with the screen off for more than 40 minutes without any problems. The app runs in the background with an audio player running in the foreground.

The only modification is that I have activated developer mode on the phone. But that shouldn't make any difference.

1 Like

Hi all, thx for your answers.

Yes I did

I tried it works.BUT:
You display the result inside the app. If you send a notification using the notificationstyle ext it stops sending notifications after a few minutes. I send you the file to test it yourself (screenshot below). This tells me that only some functions go to sleep.

I have developer mode also.

If you would be so kind as to try Kumaraswamy's changed code I sent. It should send a notification every 20 secs. If the phone goes to doze mode it stops sending (you can't hear the notification sound anymore). When you wake the phone it starts counting again (time is increased cause it has added the time before it goes to doze mode).

ItooXCount_copy.aia (115.7 KB)

Aha, then its definitely the phones, I have to check for possible solutions to this, they are mostly device specific issues.

Hi, try to do this thing, before you close the app in the recents menu, do a long press on the application and select the "lock" option that would lock the application (will therefore keep it running)

Sorry I don't get where to do the long press.

In almost all Chinese phones, you get an additional app management option called "App lock" that would prevent apps from dying out.

Just click the recents button (=) and try to find for a lock option, it will probably work then.

Check this, I found a quick video on youtube.

ok that's a different App lock than the one I found in the settings which locks apps with password. The one I found cause the notifications not to work properly (shows only the number of notifications you have but not their full description)

I'm trying yours and will get back to you

1 Like

Try this one:

Click on the "Start..." button, turn off the screen and wait. A ticking sound should be heard every 5 seconds.

Same result.Stops after a while

Will have to send this to mobile through cable when I get home. Won't let me send it through mail

No problem via email, but Gmail does not accept APKs.

Since you are using the project for personal use, we could try with IGNORE_BATTERY_OPTIMIZATION permission, I guess that one of @Taifun's extension offer this feature?

I tried and it doesn't work continuously. You can hear the sound sporadically in random occurrences. From a few secs to minutes. That's strange. I think in doze mode it should wake up in fixed periods.

Your app works only if it's open. The app with the Itoo extension woke up at 10 min intervals, which seems more logical.

This is all android background stuff which needs an expert to clarify

I've been working with background stuff for years now, yet im still not an expert, there is a lot of unnecessary diversity in the Android ecosystem.

Try this thing that allows you to ignore battery optimizations. By Taifun:

It is important to note that when you use Itoo, it automatically applies indefinite wakelock by default, so using UrsAI2WakeLock extension wouldnt make a difference.

I have almost 20 test devices, most of them with Android ≥ 6 (i.e. after the introduction of Doze mode). The APK works on all devices. So it must be a device-specific "abnormality".

More specifically all Chinese device abnormality. Xiaomi, Oppo, Vivo, Realme, Hawei, Lenovo suffer from same issues. (Well its a feature, not a bug!)

I have also Xiaomi, Huawei & OnePlus devices. No issues.