Android Question Reason for widget automatic update?

William Hunter

Active Member
Licensed User
Longtime User
I have written a widget that displays the battery level on both discharge and charge. I have set the update interval to 30 minutes. The widget runs as it should with this interval setting. I think that automatic update is used to prevent the OS from dropping the app, but I don’t know this for sure.


Could someone explain the reason for the need of an automatic update? I know my widget will run with auto update turned off, but is there a valid reason not to go this way? Also, why would there be a need for a range of varying intervals, and how does one decide on just what a particular interval should be? Any help would be greatly appreciated.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
The way I did it in my app, which lets users have multiple widget types, is that the user can pick a different update delay for each widget. Animated widgets can set their own delay, bypassing the setting.

But yes, a small delay (15 minutes or so?) is what I heard keeps the app in memory
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
The automatic update should only be used if you want to create a widget that is updated every x minutes. For example a weather widget that checks for updates every hour.
@NeoTechni & Erel – Thank you both for your responses. I need a little further clarification. NeoTechni’s statement, “But yes, a small delay (15 minutes or so?) is what I heard keeps the app in memory”, confirms what I have read elsewhere.


Whereas, Erel’s comments seem to indicate that automatic update is only used to update data input from an outside source (Internet), and has no effect on keeping the app in memory. With this in mind, it would seem that my widget should have automatic update set to 0.


Erel would you please elaborate on this? I’ve read a number of conflicting comments on this subject, and things are still unclear to me.


Best regards
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should not force your app to stay running. Your app should only run when it needs to.

How are you intercepting the battery level? With PhoneEvents (dynamic receiver)?
If yes then then the interval will determine when the widget will be updated. This is not always the case.

See this tutorial: Intent Filters - Intercepting SMS messages in the background

If I remember correctly you cannot create a static receiver for the battery intent which means that you should rely on the automatic updates mechanism.
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
My widget service receives email at user defined intervals, by default 15 mins (using StartServiceAt).

Is there any merit in using stopservice after each mail fetch? Will the widget service still be able to service widget events if I do?
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
For those interested:


1. Yes, I am intercepting the battery level with PhoneEvents.


2. The only way I could get my widget to continue monitoring battery level without interruption was to leave the update interval set to 0, and use the line of code below, to start the service every 15 minutes.

B4X:
Sub Service_Start (StartingIntent AsIntent)

  StartServiceAt("",DateTime.Now + 900 * 1000,True) 'every 15 mins

End Sub


Thanks to all who replied to my query.
 
Upvote 0
Top