Android Question StarterService with Widget on SDK 29 not getting called

Acuario

Member
Licensed User
Longtime User
Hi,
I am playing with the Widget clock from the tutorial:
https://www.b4x.com/android/forum/t...widget-more-frequently-than-30-minutes.11329/

It works ok from the sample code but I get a warning in the log:
The recommended value for android:targetSdkVersion is 29 or above (manifest editor). (warning #31)

So I updated the Manifest to:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>

Now the Widget displays but does not get updated. I added some logging to the code and I see that the line 'StartServiceAt......' is called but the service never gets restarted.

Here is my log from the working widget with the following in the manifest '<uses-sdk android:minSdkVersion="4"/>':
Logger connected to: Xiaomi Redmi Note 9 Pro
--------- beginning of main
** Receiver (widget2x1) OnReceive **
*** Service (widget2x1) Create ***
** Service (widget2x1) Start **
Service started in foreground mode.
Call to Service_Start:android.appwidget.action.APPWIDGET_ENABLED
Startservice:1604033520000
** Receiver (widget2x1) OnReceive **
** Service (widget2x1) Start **
Service started in foreground mode.
Call to Service_Start:android.appwidget.action.APPWIDGET_UPDATE
Startservice:1604033520000
** Receiver (widget2x1) OnReceive **
** Service (widget2x1) Start **
Service started in foreground mode.
Call to Service_Start:android.appwidget.action.APPWIDGET_UPDATE_OPTIONS
Startservice:1604033520000
** Receiver (widget2x1) OnReceive **
** Service (widget2x1) Start **
Service started in foreground mode.
Call to Service_Start:
Startservice:1604033580000
** Receiver (widget2x1) OnReceive **
** Service (widget2x1) Start **
Service started in foreground mode.
Call to Service_Start:
Startservice:1604033640000

And here is the log from the Widget that does not get updated with the manifest '<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>':
Logger connected to: Xiaomi Redmi Note 9 Pro
--------- beginning of main
** Receiver (widget2x1) OnReceive **
*** Service (widget2x1) Create ***
** Service (widget2x1) Start **
Service started in foreground mode.
Call to Service_Start:android.appwidget.action.APPWIDGET_ENABLED
Startservice:1604032800000
** Receiver (widget2x1) OnReceive **
** Service (widget2x1) Start **
Service started in foreground mode.
Call to Service_Start:android.appwidget.action.APPWIDGET_UPDATE
Startservice:1604032800000
** Receiver (widget2x1) OnReceive **
** Service (widget2x1) Start **
Service started in foreground mode.
Call to Service_Start:android.appwidget.action.APPWIDGET_UPDATE_OPTIONS
Startservice:1604032800000
 

Zoran Vujacic

Member
Licensed User
I rarely write but I have worked a lot and read about the background (foreground) app.
Xiaomi phones require to lock app in recently used apps.

They simply stop all applications that are not locked in memory.
It cannot be solved programmatically.
1. press the "Recently used apps" button
2. long click on Your apps
3. press the padlock icon

I hope I helped you a little
 
Last edited:
Upvote 0
Top