I have a widget im trying to update the TextView
using a timer:
public void onUpdate(Context context, final AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++) {
final int appWidgetId = appWidgetIds[i];
Intent clockIntent = new Intent(context, DeskClock.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, clockIntent, 0);
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.digitalclock);
views.setOnClickPendingIntent(R.id.rl, pendingIntent);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
java.util.Date noteTS = Calendar.getInstance().getTime();
String time = "kk:mm";
String date = "dd MMMMM yyyy";
views.setTextViewText(R.id.tvTime, DateFormat.format(time, noteTS));
views.setTextViewText(R.id.tvDate, DateFormat.format(date, noteTS));
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}, 0, 1000);// Update textview every second
}
}
Problem is, it only updates the once and never again afterwards. Where am I going wrong?