The closest example of what i want to accomplish is the "Engadget" widget.
It updates it's data from the internet every 5-10 minutes and "scrolls" to the stories every 5-7 seconds.
I imagine it sets the 5 -10 minutes interval to the widget's provider
to call the onUpdate without the inbuild limitations , something like that ..
AlarmManager alarms = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarms.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), updateRateSeconds * 1000, newPending);
Then the real issue.. to update the widgets content without calling onUpdate.
Here i imaging that inside the widget provider exists a timer or a Runnable that everytime it get's called it reschedules itself with something like that
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
...
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postDelayed(mUpdateTimeTask, 1000);
}
.
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
final long start = mStartTime;
long millis = SystemClock.uptimeMillis() - start;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
...
mHandler.postAtTime(this,start + (((minutes * 60) + seconds + 1) * 1000));
}
Then on widget provider inside
onDeleted
and onDisabled
i removeCallbacks mHandler.removeCallbacks(mUpdateTimeTask);
Is there anything wrong with that scheme?
Do i need to make a service to update the widget from there and keep it alive without setting an AlarmManager
to the widget's configuration?
For some reason i get double calls on onUpdate
and the runnable keeps running after i delete the widget.