Yes it is very bad idea to update widget using 10 milliseconds interval.
I have got the same problem as you and try many different solution.
If you want frequently update your widget there is two solution:
- Use AlarmMenager and next run Intent every interval millis
- Use Service and update RemoteView
The first one is very good when you create clock and you need 1 second interval. But when you need interval < 1 second its not god - problem with delay intent. For your purpose use Service, RemoteView is not a standard view the prons is that you can update that view from any place, this is a code:
public class WidgetService extends Service {
private ScheduledExecutorService scheduleTaskExecutor;
public WidgetService() {
}
@Override
public void onDestroy() {
super.onDestroy();
scheduleTaskExecutor.shutdownNow();
scheduleTaskExecutor = null;
}
@Override
public void onCreate() {
super.onCreate();
scheduleTaskExecutor = Executors.newScheduledThreadPool(1);
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
final Context cx = this;
final long startTime = SystemClock.uptimeMillis();
scheduleTaskExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
//logic here for example
RemoteViews rv = new RemoteViews(this.getPackageName(), getLayoutId());
}
}, 0, 10, TimeUnit.MILLISECONDS);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Be careful with onUpdate method there is a very serious bug and onUpdate method is called even your widget is not visible so android create phantom widgets, http://code.google.com/p/android/issues/detail?id=2539,