Android Question Home Widgets w/Timer

drgottjr

Expert
Licensed User
Longtime User
updated my little home widget using the new receiver module. running happily for a while now on first try on 2 devices (androids 12 & 13, respectively).
i thought i would try using a timer to update the widget. i mean, from the b4a point of view, we don't see it as a service anymore that needs to be restarted. the widget is running all the time, no? (until stopped.) so i turn off automatic updating and use a timer for tighter granularity (stock quotes).

anyway, does a timer potentially pose problems for/with the new receiver module?
 

drgottjr

Expert
Licensed User
Longtime User
does your widget example expect to be killed at some point? like, a few minutes later? hours? if so, why? what's the point of, eg, configuring a widget to run every hour if it's going to be killed? or are you saying that my widget will be killed because i turned off automatic updating and use a manual update? that if i stayed within automatic updates' confines, it woudn't be killed? android's silly weather widget seems to run forever.

i thought the os handled widgets differently than a user app that tried to run forever or tried to wake itself up periodically forever.
 
Last edited:
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
as I understand, the Receiver Sub that gets called does not have any access to any of the other modules data, so, for example, a SQLite DB that is usually opened in the Starter service, won't be available and should be opened again in the Receiver module
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
and should be opened again in the Receiver module
the Receiver have a very short lifetime. I dont think it is expected to do much work in it.

Q. Can receivers do everything that services can?

A. No. Receivers run for a short time. There is no similar feature to foreground services where a service can continue to run in the background indefinitely.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i would expect it to work if you just do a quick save of anything.
But running the receiver for a longer time not. You can start an activity to be able to start a service for longer tasks i guess.

Never used any Receiver actually. At least not with B4A 12.2 Beta....
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
what really puzzles me is that I currently have a widget-based app, published with target sdk 31, running on an Android 12 phone, which still uses the old widget code with StartServiceExactAt and no Receivers at all, and it works
namely this one:
 
Upvote 0
Top